Unloading AnimationTracks from Animators

No? I want to be able to take an animation track -
local track = Animator:LoadAnimation(AnimationObj)

and then unload the track when I need to, I am unsure if deleting it counts as unloading it.

1 Like

Okay I just wanted to check if deleting the track is the same as unloading it lol thanks!

2 Likes

Oh why didn’t you say so earlier then I would’ve understood, you can clone the track and parent it in somewhere like repstorage/serverstorage, which gives it the illusion of being “destroyed”, then when you need it get it from repstorage.

1 Like

You can’t clone a track it’s not an in game object

1 Like

You can’t? My life is a lie.

30char

1 Like

Actually no wait you can, I just checked on studio my life isn’t a lie.

1 Like

You are thinking of an Animation Object - all that does is hold the animation Id. I am talking about a track

local track = Animator:LoadAnimation(AnimationObject)

this loads it onto the animator, I wanted to know if there was a way to unload it

3 Likes

Yes I am saying you can clone the track.

1 Like

Cloning it doesn’t unload the track from the animator tho… it just makes a new track

1 Like

Well yeah but that’s the closest you can do, because like you said you wanna use those tracks in the future. You can clone that track and then load the cloned one later.

Sort of like how people bring back a part to life, they hide it in repstorage/servstorage, and then they put it back in wrokspace. Not actually destroyed, an illusion.

1 Like

I don’t think you’re understanding my problem.

There are a maximum of 256 tracks allowed to be loaded on an animator at once. My game will have a lot more than 256 animations, hence I want to be able to unload and load tracks at will.

You cannot clone and move a track to ServerStorage because it isn’t an in-game instance. It is just a variable in a script. And even if I could do that, it would not solve my issue because that “cloned” track is still LOADED onto the animator.

3 Likes

Yeah I just looked back and realised I was talking gibberish, english still isn’t my first language but i’m taking lessons to sorta understand it. I hope I’m making sense right now.

But yeah you can’t clone the tracks I realised, but you can destroy them

I think the “unloading” word got me confused, if you were just asking how to destroy them I wouldn’t have gotten confused.

But by the way “:Destroy()” is deprecated, instead use debris service to destroy the instance effectively:

local Debris = game:GetService("Debris")

Debris:AddItem(track, 0)

: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.