Issue Preloading animations

So I’m working on a backpack system similar to the last of us and It works pretty well, however Im experiencing a minor issue with a small visual animation bug.

The way it works is that there is a open animation, and then when that is finished we switch to the idle animation and then when a button is released we play the close animation and close it.
The problem is occuring when we transfer from the open animation to the idle.

the idle will “hesitate” and the character will glitch back to its normal state before proceeding to play the idle.

it only happens when the backpack is opened for the first time,
which leads me to the conclusion that its an issue with preloading.

Here is a small portion of the backpack animation system (which is server sided)

local openTrack = Animator:LoadAnimation(openAnim)
local closeTrack = Animator:LoadAnimation(closeAnim)
local idleTrack = Animator:LoadAnimation(idleAnim)

idleTrack:Play()--====
idleTrack:Stop()-- i have tried this to get rid of the bug

local closeDuration = closeTrack.Length
local failSafeTime = closeDuration + 2 -- Add a buffer in case of slight delay

local function stopAllAnim()
	for _, track in ipairs(Hum:GetPlayingAnimationTracks()) do
		track:Stop()
	end
end

--Backpack animaions
if toggleStatus == true then -- Opening Bag
	backpackOpen = true
	local sound = backpackOpenSound:Clone()
	sound.Parent = character.PrimaryPart

	stopAllAnim() -- Stop all other animations to prevent overlap

	openTrack:Play()
	openTrack.Stopped:Connect(function()
		if backpackOpen then
			if not idleTrack.IsPlaying then -- Ensure idleTrack doesn't replay unnecessarily
				idleTrack:Play()
			end
		end
	end)

and then here is the preloader for animations:

for index, animation in ipairs(animationAssets) do
	loadingStatusText.Text = "Loading Animation: " .. animation.Name
	ContentProvider:PreloadAsync({animation})
end

Debris:AddItem(animationsFolder, .1)

1 Like

It could be happening due to the AnimationPriority, so try setting the idleTrack’s priority to Idle and the openTrack’s priority to Action

You can also try using the Ended event instead of Stopped. Ended will wait until the animation has faded out, and the character is back to a neutral pose, before firing

1 Like

Im pretty sure the open anim is set to action and the idle is set to idle. I will double check, but thanks for the reply.

I actually need the idle to start as soon as the open animation is finished, I want to avoid the visual bug that occurs in the first half of that video. (the second open is what i want everytime)

1 Like

Try changing the fade time for the idleTrack

Just in case you don’t know how, you can pass a number value as the first argument for an AnimationTrack’s Play method, which will be used as the fade time. By default it’s set to 0.100000001, but you can try setting it to 0, or a larger value

Sorry for the bump, but wanted to share the solution.

The main issue is with how animations preload and behave.
While ContentProvider’s :PreloadAsync probably does improve load times, it is not particularly helpful for this context.

Why?
Because animations have to be loaded on the humanoid or animator they will be played with. Otherwise you will always have that slight glitch

Solution: Load it on the players humanoid before the game begins.

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