I’ve read on the wiki that KeyframeReached only fires once for each Keyframe.
Reoccuring Keyframes won’t fire, it said.
Not sure why it’s that way, neither if it’s true, but I feel like that’s a problem.
I’ve read on the wiki that KeyframeReached only fires once for each Keyframe.
Reoccuring Keyframes won’t fire, it said.
Not sure why it’s that way, neither if it’s true, but I feel like that’s a problem.
[quote] I’ve read on the wiki that KeyframeReached only fires once for each Keyframe.
Reoccuring Keyframes won’t fire, it said. [/quote]
That’s right; API says, “Fires every time the animation reaches a new keyframe. Will not fire if the keyframe has already been used.”
HOWEVER, on the Animations Tutorial page on the Wiki, it says, “For instance, in a walking animation you could name the frames where the character’s feet touch the ground and play a sound when those frames are reached.”
I highly doubt that I want my character to make a footstep sound only the first time I take a step. That just doesn’t make any sense.
I can think of many uses for having it fire every time a Keyframe is reached, first or not; I, however, cannot think of one good reason why I’d only want it to fire once. And even if I did, I could disconnect the event or ignore certain calls. This definitely needs to be changed.
I have a walking animation that plays a footstep sound each time it reaches the “step” frame and it works fine. What the heck.
I seriously doubt only firing for a certain keyframe once, especially BETWEEN ANIMATIONS, is the intended behavior. Right now I’m simply incredibly annoyed that KeyframeReached & animation keyframes have suddenly become entirely unreliable for no reason at all.
For more proof of the new bug (KeyframeReached not firing properly after an animation has played once), go to my game and use the sword attacks (click 3 times in succession on the ground). Watch how it acts the first time on each swing, then see how it works once the animations have played a second time.
I probably can’t expect this to be fixed before the code freeze, but it’d be nice to know the issues have been taken note of for later.
Pertaining to this previous issue, I think it’s worth looking at the Animation plugin you’re using. Roblox’s Animation Editor plugin has the following code around line 2920:
-- check for end animation keyframe
local keyframe = keyframeList[animationLength]
if (keyframe == nil) then
local kfd = Make('Keyframe', {
Name = "KF" .. animationLength,
Time = animationLength,
Parent = kfs,
})
...
end
which is most likely the cause of renaming the last Keyframe. I recommend modifying the plugin, inserting this line of code just above the aforementioned code:
local animationLength = keyframeTimeClamp(animationLength)
and if that doesn’t fix it then it’s most likely due to loss of float-precision such that it doesn’t recognize the last Keyframe as the last Keyframe due to its time not being precisely the animation length. If that’s the case, I would just write a loop that checks the contents of keyframeList for an index that is significantly close (perhaps within less than half of timeScale) to animationLength.
[quote] I have a walking animation that plays a footstep sound each time it reaches the “step” frame and it works fine. What the heck.
I seriously doubt only firing for a certain keyframe once, especially BETWEEN ANIMATIONS, is the intended behavior. Right now I’m simply incredibly annoyed that KeyframeReached & animation keyframes have suddenly become entirely unreliable for no reason at all. [/quote]
[quote] I have a walking animation that plays a footstep sound each time it reaches the “step” frame and it works fine. What the heck.
I seriously doubt only firing for a certain keyframe once, especially BETWEEN ANIMATIONS, is the intended behavior. Right now I’m simply incredibly annoyed that KeyframeReached & animation keyframes have suddenly become entirely unreliable for no reason at all. [/quote]
[/quote]
Why not just time it?
After playing the animation, wait the amount of time it would take to get to that keyframe then play the sound.
You may run into a small issue the first time the animation is played since it hasn’t loaded completely. I recommend preloading all of your animations.
Doesn’t having wait()s and whatnot pause the rest of the script? The whole point of using AnimationReached was that it could be threaded through a function easily without using the hassle (and unreliability w/ animations) that waits have.
It’s super easy to create threads yourself. Events do it internally anyways.
Spawn(function()
WalkAnimation:Play()
wait(duration)
-- Code
end)
You could also use coroutines.
Just a quick reminder that this bug is still present. Compare the first set of sword swings to the second, in which KeyframeReached fails to activate at all. I REALLY don’t want to have to use workarounds for this just because a feature broke somewhere in the last couple months.
[quote] Just a quick reminder that this bug is still present. Compare the first set of sword swings to the second, in which KeyframeReached fails to activate at all. I REALLY don’t want to have to use workarounds for this just because a feature broke somewhere in the last couple months.
[/quote]
I’ve been working with animations recently and had the same issue. CodeWriter and I worked on it together.
You need to update your Animation plugin, close Studio, restart it, and edit your animation. At the end, you should have two keyframes - one named whatever you named it, and another that will be KF#.##. Delete the KF#.## one, re-export.
Does that solve the KeyframeReached breaking on other named frames bug, though? I got an easy workaround for the KF#.### bug but this new one is a doozy.
My game, which uses animations for almost everything, seems to work almost perfectly after I did this, yes.
I say almost perfectly, though, because on the first use of any animation that is shorter than, it looks like, .25 seconds, it breaks the first time. I’m considering posting a thread here about it, but no one ever seems to read my threads and I’d rather not waste the time, lol.
No dice. KeyframeReached still only works for the non-end keyframes for the first time an animation plays.
Is this still broken?
EDIT: yup
In order to have KeyframeReached events working correctly, you must not let the AnimationTrack you are playing go out of scope in Lua. If it goes out of scope, the AnimationTrack will be garbage collected and when that happens, it will no longer fire the KeyframeReached signal, since that too will be cleaned up.
What’s causing the AnimationTracks to be garbage collected? They’re all referenced at the very top of the script outside of any functions or anything. What’s garbage collecting them now that wasn’t garbage collecting them a few months ago?
Without a sample of code, it’s hard to say. Previously, I was able to identify out of scope issues with another animation script I was debugging, so I wanted to present that as a possible solution to this problem. If you are still having issues and if you have a simple reproduce case, please post a link to the simplified place and I’d be happy to take a look.
Alright, here’s the sample place, stripped down to just the custom character.
The issue is that none of the KeyframeReached functions in the Movement script (inside Guy2, the character template) work past the first use of each animation track. You can click to slash the sword multiple times to see it doesn’t do the three-strike combo properly the second time around. Rolling (pressing E while running) also “slides” after the first roll because it doesn’t fire AnimationReached for the “rollend” keyframe (yet, somehow still detects the end keyframe??)
Ok, I was able to track down the issue with your simplified place and have a fix for it. It will likely be in the release next week (unless something else comes up in testing).
Thank you!