Koreographer - Audio Driven Events, Animation, and Gameplay

No, this would not prevent you from beat syncing other states as well. You would simply need to ensure that all synced states use same Animation Parameter for their Motion Time. In theory that should be enough (I have not tried this). I have no idea what overlapping animation state transitions would look like with such a setup.

That is very true and an excellent point. I do not think there is a good* way to do this with the Animator system* unless you slam the playhead every frame with Play or use the Motion Time parameter. I have no idea what happens if you supply a negative delta to the Update method. I would not expect it to work.

Right. Would be nice, wouldn’t it. If only Unity supplied us with a way to Force a State to a specific Normalized Time, right?

(*) Welcome to Unity Dark Arts. I didn’t mention this before because Unity deprecated it, but there is a method on the Animator called [Animator.ForceStateNormalizedTime](https://docs.unity3d.com/420/Documentation/ScriptReference/Animator.ForceStateNormalizedTime.html) where you simply pass the normalized time that you would like the current base layer state to use. I mentioned that this was Dark Arts because it was deprecated back in Unity 4.3. I just checked and it appears to still exist in Unity 2019.4.15 (autocompletes, at least), but there are no guarantees that it will continue to exist going forward (or that it won’t have quirks in modern Unity versions). It appears that there are others who would like to see this API resurrected with full support (perhaps you could chime in?).

(*) Another option would be, of course, to use the “legacy” Animat**ion** system instead of the Animat**or** system. Driving the Animation system by setting time directly is incredibly trivial. You simple grab the current state and set either its [normalizedTime](https://docs.unity3d.com/ScriptReference/AnimationState-normalizedTime.html) or [time](https://docs.unity3d.com/ScriptReference/AnimationState-time.html) property.

The trick to this is to simply call:

animCom.Update(0f);

Kinda dumb, but that should be enough to have the animation Play at the time you indicated with no further time bump (I have used this trick before).

Hurray! Congratulations! My guess is that it is processing the delta time and the offset is so small that you don’t notice the difference. Regardless, it’s good to know that you got something working!

This should actually work without issue. The normalization is simply a percentage so it doesn’t matter what the actual animation length is. The reason I suggested a 1s animation is because Animator.Update uses delta time adjustments, not delta normalized time. It is far easier to treat the clock as “time in beats” that way.

That said, if you’re slamming the playhead to a normalized time (as you do with Animator.Play), then the story is different. If you have an animation timeline of any length that you simply want to loop with every beat (or whatever timebase), you can find the percentage (normalized time) of the way through that timebase (beat, eight note, bar, etc.) that the current time is through and then pass that as the percentage (normalized time) to the position controlling logic. This is one of the nice things about specifying time in “normalizedTime”.

It is possible, however, to adjust the Update values to also work with non-1s-length animations. This simply involves getting the current AnimatorStateInfo from the Animator and then multiplying its duration (AnimatorStateInfo.length) by the normalized delta time. Easy-peasy!

That’s a fair point. You might be able to encapsulate the logic you have here in an Animator State Machine Behaviour which would make setting which states are beat-matched as trivial as adding the behaviour to the states that need it. This would also be trivial if the Motion Time option works for you (which I expect it will…).

You are very welcome! Thank you for being a Koreographer user and asking your questions here where others may also benefit from the discussion! This has been a good exercise for us as well!

Best of luck with the project! Please let us know how it goes - would love to see what you’re putting together!