Branching target animations in mecanim

I’ve been trying to setup an animation controller where a state can move to different targets based on some property. Determining this value only happens at the end of the first animation (e.g. checking for a button press within a given time):

State A ---v=1---> State B
      |
      -----v=2---> State C

Note that the animations are 2D and made with matching start/end keyframes so no blending is used.

I’ve tried two approaches to this:

  1. Have an empty ‘dummy’ state after the first with an OnStateEnter script calling the logic to set the property. This works every time but, even though the transitions out of the dummy state are all zero length, it still takes a frame so causes a glitch in the animation.

  2. Have an animation event at the end of the first animation calling the logic to set the property. This avoids the glitch but even moving the event back a couple of frames, doesn’t seem to guarantee it is processed before the transition so it may be set too late and move onto the wrong state.

Is there anything anyone can recommend changing to fix one of these approaches (or give another option that could work)?

Thanks.

I’ve solved this by using a coroutine approach instead. I use an animation state behaviour to kick off the coroutine on entering the state and this then monitors the duration, calling the logic in the appropriate window at the end of the state. This seems to work flawlessly to achieve what I’m after.