Unloading AnimationTracks from Animators

:Destroy() is deprecated?? Since when

1 Like

It’s not technically deprecated, it’s kind of got the same treatment as “wait()” did.

Debris is SLIGHTLY better than using “:Destroy()” and the documentation explains it here:

1 Like

I just saw your on HD Discord server its me lol, don’t make me look like an idiot XD. Don’t tell them it was me.

By the way don’t tell them english is my first language they’re going to absolutely violate me in that chat.

uh yeah, when you call :LoadAnimation() on your animator, it returns an AnimationTrack‎ which you can then store in a table or something and destroy when it’s no longer needed. This basically “unloads” the animation track from the animator

Wrote some simple code for you to work off:

--animtion track function to load an animation on the animator
local function _loadAnimation(animationTarget : Animator, animationID : string) : AnimationTrack
	local newAnimation = Instance.new("Animation")
	newAnimation.AnimationId = animationID
	return animationTarget:LoadAnimation(newAnimation)
end

local animator = localPlayer.Character.Humanoid.Animator

--this is an animation track object
--you can store it wherever to then destroy/unload
local yourAnimationTrack = _loadAnimation(animator, "rbxassetid://0000000000")

--play the animation normally
yourAnimationTrack:Play()

--wait for your animation to stop playing
yourAnimationTrack.Stopped:Wait()

--to destroy/unload just do this
yourAnimationTrack:Destroy()
yourAnimationTrack = nil

I know how load animation and animation tracks work, I was just wondering if destroying/deleting/removing the tracks from my table is the same as getting “unloaded” and will free up the space of the 256 animation tracks allowed to be loaded. You didn’t need to provide a whole code block lol

2 Likes

yes it’s the same, but remember to also clear the reference in the table too. This is how:

--create a table to hold the animation tracks
local animationTable = table.create(256)

--add the animation track to the table you created
local yourAnimationTrack = _loadAnimation(animator, "rbxassetid://0000000000")
table.insert(animationTable, yourAnimationTrack)

--how to clear from a table
table.remove(animationTable, table.find(animationTable, yourAnimationTrack))
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.