Mecanim / Animator : how to check if a Trigger is true ?
hello
I use some parameters in my Animator, multiple bools and also a couple of triggers.
When a Trigger parameter is turned on by calling SetTrigger() it stays true until it is used in a transition and it turns false after that. I really need that behavior, so I don't want to use bools instead.
I need to know at some point if a trigger is true. I mean that it has been turned on, but the transition has not been played yet and it is still waiting for it.
There are the Animator.GetBool, GetInt & GetFloat functions, but not a GetTrigger function.
I tried the GetBool function with my trigger parameter's name, but it always returns false ...
How can I check if a Trigger has been set to true ?
Thanks in advance
Vince
Answer by LoBlanc · Dec 13, 2016 at 11:05 AM
Are you checking the Animator window? You can have a first feedback of the triggers value there:
In Unity -> Window -> Animator
Hope it helps
Answer by VinceMpl · Dec 13, 2016 at 11:10 AM
yes i see that it turns on, but I want to get that value in C#
$$anonymous$$aybe you can read it like it was a bool, though Im not sure
If you can't use ResetTrigger() in some way, I think you'll have to use a bool.
Answer by theonlysake · Apr 15 at 08:02 PM
It is very simple (If you haven't already figured it out):
Animator animator = GetComponent<Animator>();
bool triggerValue = animator.GetBool("TriggerName");
A Trigger is just a Bool that is consumed (turned to false) once used, so it can be accessed the same exact way :)
Your answer
Follow this Question
Related Questions
Problems with using the same Animator Controller on multiple objects. 0 Answers
Trigger Parameters not working inside Animator Trigger action 0 Answers
Creating Humanoid Animations in Unity 0 Answers
Mecanim state that keeps last pose? 0 Answers
Mecanim: 2-step transitions in a single update (skip intermediate state) 0 Answers