Skip to content

Conversation

@lack-of-gravity-jack
Copy link
Contributor

Changes

animation controller methods are deprecated in favor of directly using animator

there's some code samples I want to change but I don't know how to. Where can I find it? "Please note that AnimationPlayed is a member of both Humanoid and AnimationController which this example would also work on." <- i cant find this line but i see it on the docs page

Checks

By submitting your pull request for review, you agree to the following:

  • [ x] This contribution was created in whole or in part by me, and I have the right to submit it under the terms of this repository's open source licenses.
  • [x ] I understand and agree that this contribution and a record of it are public, maintained indefinitely, and may be redistributed under the terms of this repository's open source licenses.
  • [x ] To the best of my knowledge, all proposed changes are accurate.

@lack-of-gravity-jack lack-of-gravity-jack requested a review from a team as a code owner February 16, 2025 03:28
@github-actions github-actions bot added the engine reference Changes the Engine API Reference documentation label Feb 16, 2025
@IgnisRBX
Copy link
Contributor

Hi @lack-of-gravity-jack , code samples aren't yet open sourced. Could you please tell me which sample to update (which API specifically) and then paste the full modified sample in a comment here? I'll take it from there. Thanks!

@IgnisRBX IgnisRBX self-requested a review February 18, 2025 16:23
@lack-of-gravity-jack
Copy link
Contributor Author

"Code Samples
The following code sample includes a function that prints the name of an animation whenever an AnimationTrack plays on a humanoid.

A connection is made listening to the Humanoid.AnimationPlayed and the name of the underlying animation is printed.

Please note that AnimationPlayed is a member of both Humanoid and AnimationController which this example would also work on"

Under properties: Animation
https://create.roblox.com/docs/reference/engine/classes/AnimationTrack#Animation

Suggested edit: change the description text above the code sample to remove references to Humanoid.AnimationPlayed and AnimationController.AnimationPlayed, change the code sample to use Humanoid.Animator.AnimationPlayed:Connect()
event

@lack-of-gravity-jack
Copy link
Contributor Author

Code Samples
The following code sample includes a function that prints the name of an animation whenever an AnimationTrack is played.

This script can be placed in a model with a Class.Humanoid child. The Humanoid contains an Class.Animator child, the Animator.AnimationPlayed event of which is connected to a function that prints the name of a playing Class.AnimationTrack.

Listen For New Animations
local function listenForNewAnimations(Animator)
Animator.AnimationPlayed:Connect(function(animationTrack)
local animationName = animationTrack.Animation.Name
print("Animation playing " .. animationName)
end)
end

local Animator = script.Parent.Humanoid.Animator

listenForNewAnimations(Animator)

@IgnisRBX
Copy link
Contributor

IgnisRBX commented Feb 19, 2025

Cool. So for the first code sample, I'm planning to change it to this (remove the arbitrary function and make it wait for an Animator to connect the event to).

I'm hesitant to add another WaitForChild() here, but it's probably safer than FindFirstChildWhichIsA("Animator").

local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")

animator.AnimationPlayed:Connect(function(animationTrack)
	local animationName = animationTrack.Animation.Name
	print("Animation playing " .. animationName)
end)

@IgnisRBX
Copy link
Contributor

IgnisRBX commented Feb 19, 2025

FYI, Humanoid.AnimationPlayed and AnimationController.AnimationPlayed still exist in the docs, but you have to toggle the "Show Deprecated" switch to see them.

@lack-of-gravity-jack
Copy link
Contributor Author

The Humanoid and AniamtionController's .AnimationPlayed events are deprecated, so I figured the AnimationTrack doc page should get rid of the code samples that use the event directly from a Humanoid

The changed code sample looks good. I don't get why there was an arbitrary function to set up the listener in the original either.

@IgnisRBX
Copy link
Contributor

Nice! I'll merge this and also update the code sample.

@IgnisRBX IgnisRBX merged commit 07cc2c2 into Roblox:main Feb 19, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine reference Changes the Engine API Reference documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants