In a class-based fighter I’m helping to code, we use many unique custom animations for each class’ attacks and abilities. Recently while creating a security update, I’ve started noticing this error after a minute or so of playtesting:
I did some research and apparently you have to delete tracks you aren’t using anymore, so I made sure my scripts did so when loading new attack animations. The issue still occurred, but we were still using a likely outdated copy of the Animation script, so I grabbed a fresh one and edited it to game standards. The error still occurred, so I decided to see if it happened when I didn’t use any attacks at all. The error still occurred, so I removed the edited copy of the Animation script and used the stock one provided by ROBLOX. It kept happening.
What could cause this? The only interference that takes place between the game and the default animation script is changing the IDs of the Animation objects contained within - something the script is equipped to handle, as it listens to the event intentionally. I’m not sure what I’m doing wrong that causes this error - was there some update I missed that causes Tracks to not be deletable or unable to be offloaded from the character?
Edit: I set up a print where the previous animation track is cleared to make sure it was actually occurring, and the print ran to the output exactly 256 times before the error started to show up.
I don’t really understand. If the track is getting destroyed, even if it was somehow being held in memory, destroying it should still cause it to disappear from the Animator’s load, correct? Or am I wrong in assuming this? This is occurring with the default R6 Animation script, by the way.
This happens when the code loads an animation 256 times, since that is your error, there is a issue which keeps repeating the loaded animation over and over.
In this case, there is another script loading the same animation track in a loop quickly.
When the trigger requirement for the attack is fulfilled, are you LOADING a track everytime it runs? Or are you loading the animation once (usually at the top of the script)?
I know what the error means, I just don’t understand what’s causing it.
Also, couldn’t be. The only times my class scripts load any animations is when I attack - they don’t preload anything as they’re meant to be modular in nature. As mentioned before, I used the default ROBLOX Animation script (the one you get automatically if you have no substitute in StarterCharacter), and this still occurred when I didn’t attack at all.
I use a central module for creating and loading attack animations. It won’t call LoadAnimation if the requested Animation ID already exists somewhere.
function Core:CreateAnim(Character, id, name)
if Character and Character:FindFirstChild("Humanoid") then
local Humanoid = Character.Humanoid
local Animation, Track
local Concat = "rbxassetid://"..id
if RUN:IsClient() then
for _,prefab in pairs(CurrentTracks) do
if prefab.Animation.AnimationId == Concat then
return prefab
end
end
Animation = Instance.new("Animation")
Animation.Name = name; Animation.AnimationId = Concat
Animation.Parent = Humanoid
Track = Humanoid:LoadAnimation(Animation)
if #CurrentTracks + 1 >= 256 then
for _,track in pairs(CurrentTracks) do
track:Destroy()
end
else
CurrentTracks[#CurrentTracks + 1] = Track
end
else Animation = RS.Animations:FindFirstChild(name) or Instance.new("Animation", RS.Animations)
Animation.AnimationId = Concat; Animation.Name = name
Track = Humanoid:LoadAnimation(Animation)
end
return Track
end
end
However, this is irrelevant. As mentioned, this error occurs if I don’t attack at ALL (which is the only time my class scripts load animations, they don’t pre-load), and when I’m using the default ROBLOX Animation script.
The default ROBLOX Animation script assigns each loaded track to a variable, then destroys whatever track is under that variable each time it plays a new Animation. By all logic, this shouldn’t be occurring. But it is. And I have no idea why - the tracks ARE getting destroyed.