- Home /
animator controller setTrigger problem
hey guys i have simple and annoying problem i just wanna animate my character to specific movement in specific moments but i doesn't seem to work my code here, very simple
animator.SetTrigger("Idle")
animator.SetTrigger("Run");
if it execute itself, character should animate as "Run". but it is actually "Idle" i have no idea what's going on here. maybe it happens by the particular properties of each anim?? here is the my anims info
You should put whole code, not only trigger - we know how trigger looks like. We don't know where and how did you put the trigger in your script.
Answer by Pinkuboxu · Jan 01, 2018 at 08:56 PM
I think I would need to see the whole context of where you are using the code. But my guess is that you aren't using Animator.ResetTrigger() to turn the one you aren't using off.
So, something like this maybe(?):
// when you want to idle
animator.SetTrigger("Idle");
animator.ResetTrigger("Run");
//when you want to run
animator.SetTrigger("Run");
animator.ResetTrigger("Idle");
I would probably need to see the full context to help anymore though.
Triggers are automatically consumed and reset as soon as the next transition occurs, so really the only time it's necessary to reset triggers manually in this way is if one part of a script decides to trigger one animation, while another part (in the same frame) decides to override that command and trigger something else entirely. While it's possible that's happening here, my advice would be to advocate conditional trees and only firing the trigger that's actually needed for the task at hand ins$$anonymous$$d.
Not saying you're wrong exactly, but that controlling an animator is far cleaner when people forget that ResetTrigger even exists. $$anonymous$$ore info on this problem is definitely needed to give a solid answer I think.
Well, I don't $$anonymous$$d being wrong. Being wrong is one of my favorite things because I learn a lot from being wrong and making mistakes. The $$anonymous$$iss Frizzle $$anonymous$$ethod. That's one of the reasons I've started trying to help on Answers because I can make suggestions and get corrected if I'm not correct, either way I'm part of being helpful. Even if I'm wrong, it stands as a means to show others what not to do. I'm not so much interested in pride as I am progress.
Your answer
Follow this Question
Related Questions
spawns without controller-: Object reference not set to an instance of an object--but i swear it is! 1 Answer
Animations don't work with humanoid avatars 0 Answers
blend tree animation through script? 0 Answers
Get back to non-animated type of the character while animating. 0 Answers
How do I check, and change, the current frame/time of a sprite animation in Unity 4.3? 0 Answers