Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Animation Blend Tree - SpriteRenderer.Enabled

Discussion in '2D' started by edammer, Aug 20, 2016.

  1. edammer

    edammer

    Joined:
    Aug 20, 2016
    Posts:
    5
    Hi,

    I have a number of character idle animations and a number of action animations.
    Rather than have have individual states for the different idle animations and transitions to each action, I tried creating a blend tree with the different idle animations in the tree.
    The correct idle animation is controlled with a parameter.

    2 of the animations work OK but one does not seem to work at all.
    This animation switches the displayed sprite by using SpriteRenderer.Enabled.
    I can see that the correct animation is selected by the blend tree.

    The animation works ok when not in the blend tree but not when in the tree.

    Is this something you can't do with blend tree and if so, what are the other options to achieve the same thing (switch sprites).

    Thanks
     
    Last edited: Aug 25, 2016
  2. PeaceLaced

    PeaceLaced

    Joined:
    Jun 2, 2015
    Posts:
    53
  3. edammer

    edammer

    Joined:
    Aug 20, 2016
    Posts:
    5
    Thnaks PeaceLaced.

    I have the blend tree working OK but its just the changing of SpriteRenderer.Enabled that does not seem to be working.
    The animation works OK outside the blend tree but not inside it.
     
  4. edammer

    edammer

    Joined:
    Aug 20, 2016
    Posts:
    5
    On further investigation, it seems to have nothing to do with the SpriteRenderer.Enabled.
    I changed the animation to use scale = 0 or 1 to hide and show the sprites instead and it still does not work.
    If I set the animation to loop it works (but loops as expected) but if I remove the loop it does not run even once.
    The only time I can get the animation to work without looping is to make it the first in the blend tree.

    If I make that animation the first in the blend tree it runs once but never again until I move out of that animation state (the tree) to another animation not in the tree and back again it works again the first time.

    The animation in question is LookAtCam in the below examples.
    The threshold setting is a float.

    If my blend tree looks like this it works the first time but not again, the other 2 animations work every time:
    1. LookAtCam - threshold = 0
    2. Idle - threshold= 1
    3. LayDown - threshold= 2

    If the tree looks like this, the animation never plays correctly, the other 2 always play correctly:-
    1. Idle - threshold = 0
    2. LookAtCam - threshold= 1
    3. LayDown - threshold= 2

    It only seems to be the LookAtCam animation that does not work correctly.

    If I use the LookAtCam animation outside the blend tree then it works but my animation controller is becoming a bit of a mess.

    I might have another look at the linked posted by PeaceLaced.
    One of the links was changing the states in the blend tree in code rather than setting up the blend tree and using the param to control the active animation.

    It would be nice to know why only 1 of my 3 idle animations has an issue but the other 2 work ok.

    Then only thing that appears to be different now (after removing the SpriteRenderer.Enabled) is that the LookAtCam is a long animation (10 seconds) and the others are quite short ( < 3 seconds).
     
    Last edited: Aug 25, 2016
  5. edammer

    edammer

    Joined:
    Aug 20, 2016
    Posts:
    5
    OK, a bit more info.

    It looks like the animation is just going straight to the last frame in the animation, in this case the last frame is the same as the base model so it looks like its not working.

    The other non-looping animations have last frames that are different to the base model so appear to work.

    I'll try and transition out of the blend tree and back again and see if that works.
     
  6. edammer

    edammer

    Joined:
    Aug 20, 2016
    Posts:
    5
    I have switched to using a sub state machine to achieve this.