As a Roblox developer, it’s currently too difficult to call to animations that are loaded or created in two separate functions within the same script, without bloating your script with extra variables.
My current usecase is being able to Load Animations into an AnimationController of a ViewModel, and then play the animation in a Fire function, Equip Function, etc. etc. However, with the way Animations currently work, you have to create multiple different variables that will index upon the animations being loaded. This creates a tremendous amount of bloat to a script. Admittedly, I could be doing it wrong, but I digress.
So I propose these new APIs, which will allow direct access to currently loaded animations:
PlayAnimation('string' name)
StopAnimation('string' name)
This seems a lot more intuitive to me and would signficantly cut down on the number of variables required to handle something like this.
You could, in theory, write code that looks like this:
for i, v in pairs(Animations:GetChildren()
AnimationController:LoadAnimation(v)
end
--Fire Function--
function fire()
AnimationController:PlayAnimation("FireAnim")
end
function equip()
AnimationController:PlayAnimation("EquipAnim")
end
instead of like this:
local Fire = nil
local Equip = nil
for i, v in pairs(Animations:GetChildren()
AnimationController:LoadAnimation(v)
if v.Name == "FireAnim" then
Fire = v
elseif v.Name == "EquipAnim" then
Equip = v
end
end
function fire()
AnimationController:PlayAnimation(Fire)
end
function equip()
AnimationController:PlayAnimation(Equip)
end
You also would not need to create multiple variables for different objects, making the code much, much cleaner.