Search Unity

SetTrigger() sometimes not working for all layers

Discussion in 'Animation' started by ratking, Feb 28, 2017.

  1. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    350
    Hallo,

    I have a simple Animator with two layers. Both layers have a single state that each have a transition from the Any State. This transition is activated by a trigger. The problem is that sometimes - not always - when I call SetTrigger() the trigger only activates one of the states. This behaviour is pretty random, and I wonder if there's a bug with triggers, or if I might be doing something wrong.

    Regards,
    ratking
     
  2. shihui142857

    shihui142857

    Joined:
    Oct 21, 2016
    Posts:
    12
    I have the same problem with Unity 2018.3.9f1
     
  3. shihui142857

    shihui142857

    Joined:
    Oct 21, 2016
    Posts:
    12
    The SetLayerWeight method sometimes also not work for me, must use SetLayerWeight in Update to make it work.
    The bugs fly in Unity 2018.3.9
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    A trigger is a bool that gets set back to false after it triggers its transition, so if it doesn't trigger both in the same frame for whatever reason then it won't continue trying to activate the second one.
     
  5. datagreed

    datagreed

    Joined:
    Sep 17, 2018
    Posts:
    44
    Same problem in 2019.4.3 LTS version
     
  6. ViktorMSc

    ViktorMSc

    Joined:
    May 28, 2022
    Posts:
    14
    I fixed the same issue after reading the docs. My second layer was not recieving my attack animation trigger.

    So, the triggers are enabled until consumed by a listener.

    When I removed the transition from my main layer, the second layer got the trigger event.

    So you basically have to have a single trigger for each layer to make sure both layers recieve the trigger.
     
  7. haraldbackfisch

    haraldbackfisch

    Joined:
    Jun 19, 2023
    Posts:
    1
    I just encountered the same problem, it is behaving rather weirdly though.
    Say you have three animations: Idle, Attack, Death.
    Idle is the default state after Entry.
    Attack state transitons from the Idle state on receiving a trigger, which does not work for all layers.
    Death state transitions from the Any State node on receiving a different trigger, which does work for all layers.
    While this can be a workaround for some situations, I really dislike having to set up individual triggers for each layer if its the same action.
    I have a strange composite sprite thing going tho, so i guess I chose the suffering lol, if anyone is stumbling over this with a similar situation (sprites!), check out ECS (more primitive, code-based approach) because thats what i'm gonna do now to move away from the animator workflow which is a hassle with a lot of clips.


    Edit: I discovered this because I accidentally had it set up like describe above, now i went back to i switch Attack to also transition from Any State but it still does only work for two layers more... it is confusing
     
    Last edited: Jul 2, 2023