Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

How do I programmatically swap sub-state machines while maintaining its current state?

Discussion in 'Animation' started by vspin, Mar 19, 2022.

  1. vspin

    vspin

    Joined:
    Mar 29, 2014
    Posts:
    22
    How do I programmatically swap sub-state machines while maintaining its current state? My isometric 2D game has 4 map rotations for each corner of the map. When the map is rotated, all the characters animations are changed based on the new rotation. For example, if the map is rotated, and my character is faced in the Direction1 sub-state machine but now need to be in the Direction2 sub-state machine, how do I swap the character from Direction1 sub-state machine to Direction2 sub-state machine while maintaining the current state within the sub-state?

    ............................... ..........<Root>
    ..........................................[default]
    <Direction1>....<Direction2>.....<Direction3>....<Direction4>
    ......[Idle]................[Idle]..................[Idle]...............[Idle]
    .. ...[Run]...............[Run]..................[Run]....... ......[Run]


    Thank you for your time.
     
    Last edited: Mar 19, 2022
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,580
    Some people would use Blend Trees for that rather than sub states. If both Blend Trees use the same parameters they'll automatically be playing the correct direction when you swap between them.

    I wouldn't really recommend that approach because the setup process would be rather tedious and it would be annoying to maintain later on when you have lots of similar characters, but I can't actually tell you what I'd recommend because advertising isn't allowed here (except in signatures).
     
    vspin likes this.
  3. vspin

    vspin

    Joined:
    Mar 29, 2014
    Posts:
    22
    Thank you.