- Home /
Trigger the same state again?
I have a current setup where if you pick up an item, the animation is set to trigger on the UI Canvas to show "+10 Health!", it all works fine the first time, but afterwards I am unable to trigger it again when I pick up another item.
EDIT: Unity Version 4.6.1
The trigger is set by:
healthanim.SetTrigger("HealthUp");
where healthanim is:
GameObject.FindWithTag("HudCanvas").GetComponent <Animator> ();
If anyone has any thoughts on the matter it would be highly appreciated, I'm still new to Unity and trying to learn the ropes so if there is a better way to achieve what I am trying to do, feel free to suggest that too!
EDIT: My Mecanim Animation Thing
why don't you use just an animation component for such simple animations. I mean, you don't have to switch states right? I don't have any suggestions about your problem tho... :/
This probably happens because your new AnimationState does not have a return transition back to the default where the trigger HealthUp is set to work.
@GameVortex I was using mecanim to handle the animation, and to my understanding a trigger should go back to the default? Or am I misunderstanding how triggers work?
@taxvi The Animation component is deprecated. @WToa is correct to be using Animator.
@GameVortex There is a transition from "Any State" to "Health Up" (which we assume is linked to the HealthUp trigger), so it shouldn't matter that there is no transition back to default.
@WToa Play your scene with the Animator selected and you'll be able to see the transitions as they occur. Can you confirm what state the animator is in at the point the "Health Up" transition is no longer occuring? If it remains in the "Health Up" state, do you have the "Transition to Self" option enabled in the transition from Any State?
A transition can be activated by a trigger. When activated the current state transitions to the other state. How that state can transition to other states again depends on the transitions connected to it. You can activate the Trigger again but if no transitions in the state is listening to the trigger, nothing will happen.
But it does seem like you have a transition in the AnyState which is listening to the trigger? If that is the case then it should work. Have you looked at the animatorcontroller during runtime? You can easily then see which states and transitions are active. It might be that the state is actually activated but something else is preventing the animation to be shown properly, or maybe the code does not get to the SetTrigger function the second time. Try to add some debug.log to where you set the trigger.
Answer by tanoshimi · Jan 16, 2015 at 09:45 AM
Ah, I see :) Also, I believe that whether a state is allowed to re-enter itself is a behaviour that has possibly changed in different versions of Unity, so it would be helpful to know which version the OP is using. (discussed somewhat in http://forum.unity3d.com/threads/mecanim-any-state.158661/)
Thanks to @tanoshimi for showing me the solution.
Based on my problem, what you have to do is to check Enable Self Transition on the arrows leading out of Any State, the checkbox itself is shown here:
Your answer
Follow this Question
Related Questions
Mecanim - Trigger event Invokation 0 Answers
Mecanim - Trigger event at end of animation state 4 Answers
Mecanim - changing animation clip speed, through script? 4 Answers
Mecanim - How to figure out the State and layerIndex that triggered Animation Clip Event? 0 Answers
How to get all states and state machines in the Animator on Android? 0 Answers