Is it possible to make something happen on a specific frame of an animation?

I’m developing a fighting game. I need to make hitboxes spawn on specific frames of a character’s animations.

However, Unity’s animation system doesn’t play animations frame-by-frame; it updates the animation depending on how much time has passed since the animation started. Is it possible to change that?

Is it possible to have a specific number of steps per second, so that steps and framerate are always synchronized?

Is it possible to make Unity only update an animation once per step, or after a set number of steps?

Is it possible to make something happen on a specific frame of an animation?

Is there some other method that I’m not thinking of, which is ideal for getting hitboxes to appear at exactly the right times?

Pre-mechanim you could add events to the animations at specific times. The events will call a defined function in an attached script. I believe this will come to mechanim in the future? So if your using Animation clips with the older animation system then yes you can, if your using mechanim then not at the moment.

k

You can do it in Mecanim with Pro, by using animation curves to set a float which you could reference in a script.

Is it possible to make sure that absolutely every frame of an animation plays in Unity? Is there any way to switch it from time-based playable to framerate-based playback? Is there any way to lock the framerate to 30 or 60 FPS so that not a single frame is missed?

It seems that Animation Events always play regardless of whether the frame actually played or not. Previously I was under the impression that the animations were synced to the frames individually not the overall time but you learn new things every day. PC could keep up exactly to make it appear that animations were synced to frame, phone cannot in certain areas with high graphic settings.

So even though animation events are set to individual frames of the animation the Update() can skip that frame while the event will still trigger. I guess the first time value that Unity detects on or after the event is what calls the function? Or maybe the animations are not truly synced to Update they just attempt to be but have no real connection other than visual replication?

I donno I was trying to find exactly how this works once I found out about this tonight but of course Unity documentation does not give the exact details it seems :frowning:

But I guess the events work so that’s all that really matters although this caused some initial confusion setting up my animation progress bar based on frame rates instead of animation.time and going from PC to phone…