Deprecating LoadAnimation on Humanoid and AnimationController

Yeah, Animation objects are just asset id holders. It’s absolutely redundant. This is on our radar, but no promises.

8 Likes

Technically yes, but would still recommend against it. Because again, if you call it too early it will create its own desyncronized animator and replication will be broken. If you know the Animator already exists, it’s technically safe to call them.

Even if this wasn’t a foot-gun waiting to happen, we’d still want to deprecate it. What’s the point of having three different classes expose the same API when only one of them actually implements it? In the future we won’t add any new generic animation APIs to Humanoid and LoadAnimation, only Animator.

6 Likes

An Animator will be created for you on the server if it is spawned by the the default character loader or created from a HumanoidDescription. So for player characters spawned by Roblox code, it should be safe to assume they will already have an Animator from the server.

For anything you’re assembling manually or for some NPCs this might not be guaranteed. You can either add an Animator to the model yourself, or create it from server Scripts. Personally I’d just do the former and throw a clear error if WaitForChild("Animator") ever returns nil in my animate script.

4 Likes

it was made so we can replicate animations client and server side.

1 Like

How would I migrate my animation code to prevent using deprecated functions?

Nevermind, I figured out with some help on a topic I made recently to figure out a problem I ran into.

1 Like

The original post literally says what you need to do lol.

1 Like

instead of the humanoid, you direct it to the animator INSIDE the humanoid

2 Likes

I’ve been trying this approach for my NPC creatures, but Studio does not seem to offer “Animator” as an option for Insert Object. Is that a bug/unfinished work, or intentional for some reason?

As an experiment I tried running the game, and just grabbing an Animator object out of it at runtime using studio Copy/Paste to get one for my source model, and I’m not seeing any problems so far. Is there any risk in grabbing an Animator object that way?

1 Like

I dont think you are, even what I’ve tried, I get the same identical issue.

image

The doors don’t update until the other client goes near the train


I just gave up with animations and went over to modifying the Motor6D’s Transform property directly instead of using animators.

6 Likes

At last! This is a nicer more direct way to play animations without having to use the LoadAnimation method, this will also make animation replication a lot easier. :smiley:

This new change made my game act very weird. Sometimes animations work. Sometimes they don’t.

did you update your scripts? if not then you should migrate.

Just updated my scripts, everything works fine now.

1 Like

I thought you were going to deprecate animation controller I was about to get upset because it’s quite useful for rigs that you don’t want to have humanoid properties like health.

what? This works fine and it’s better?

1 Like

I’m having issues with this approach, I’ve tried calling this func provided here:
https://developer.roblox.com/en-us/api-reference/class/Animator

local function playAnimationFromServer(plr, character, animation)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		-- need to use animation object for server access
		local animator = humanoid:FindFirstChildOfClass("Animator")
		if animator then
			local animationTrack = animator:LoadAnimation(animation)
			animationTrack.Looped = true
			animationTrack.Priority = Enum.AnimationPriority.Action
			animationTrack:Play()
			print(animationTrack.IsPlaying)
			return animationTrack
		end
	end
end

When I try calling it directly on the client (instanced an Animator into players humanoid on PlayerAdded) the function prints true and returns the name of the track. On the server it also prints true but the track name does not seem to return/replicate to the client ( ‘-’ in output ).

Here’s the local-side code

local function onEquipped()
	if currentlyPlaying == nil then
		currentlyPlaying = true

		-- Play equip animation

		-- Play idle animation
		playAnimationFromServer(plr.Character, idle_Anim)
		print(playAnimationFromServer(plr.Character, idle_Anim))
		--animateEvt:FireServer(plr.Character, idle_Anim)
		--print(animateEvt:FireServer(plr.Character, idle_Anim))
	end
end

What am I doing wrong?

great got to change a lot of my scripts but it would probably be better i knew this would come


:sad:

3 Likes

I really wish Humanoid:LoadAnimation wasn’t deprecated. It was so much more convenient to quickly get an animation to work. And now I more lines of code just to create, find, and sometimes check for the animator object just to play an animation. Other than that, glad replication issues has been fixed

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