- Home /
Animator transition from Entry state to multiple states in Unity 5
I am making a 2d game. In this game I will have torches. When the scene starts there are two options for torches:
They may be burning
Or they may be not burning and have no flame on them.
Whether the torches should burn or not is determined by a public boolean value "IsBurning" in the script attached to the torch, so I can decide which of them are lit up in the beginning of the scene and which are not burning.
I have made all animations for Burning and not burning states and for transitions between them. Here is how the Animator is looking right now:
What I want to achieve is: If I set IsBurning in editor to true, my torch will immediately appear burning in the scene. If I set it to false, it will appear to have no light on it.
What I have tried so far is making two transitions from Entry State, but no matter what conditions I put in there (tried triggers, booleans), it automatically switches to the default state NoLight. Then, I have created a shortcut transition from NoLight to Burning State that uses a Trigger. I set this trigger in my script`s Start() function, but it does not seem to work either. Instead it is taking a long root. From NoLight it goes to LightsOn, which is gradually bringing up the light and the flame appears slowly, and only then to Burning. I have checked the order of transitions for NoLight State. My shortcut transition to Burning has higher order than transition to LightsOn, but it still chooses this longer route to get to burning state.
What am I doing wrong here? Any help is greatly appreciated.
Answer by vovo801 · Jun 16, 2015 at 05:44 AM
For people having the same problem. The SOLUTION that worked for me - in settings of my transition from NoLight to Burning state there is an option "Has Exit Time". It has to be unchecked. After unchecking this, everything works properly.
Did you ever discover a solution without using the workaround? I am having the same issue where transitions from Entry are see$$anonymous$$gly ignored, always opting for the default transition.
I am now using Unity 5, and there is even no such option now to choose Has Exit Time fot transition from entry state. But it is still working properly. In the setup i have in the example transition to NoLight is default and has no conditions on it. Transition to BurningOnWallFlicker has a condition trigger called ShortcutLit. Then in my start function i do this:
void Start ()
{
if (HasLight) {
anim.SetTrigger ("ShortcutLit");
anim.SetBool ("Lit", true);
}
}
I remember having an issue when i tried to do this in Awake, it wont work then.
Answer by Eluem · Oct 16, 2015 at 10:33 PM
Has anyone figured out how to get this to work correctly?
According to this: http://blogs.unity3d.com/2015/02/11/having-fun-with-the-new-mecanim-features/
We should be able to use this feature trivially, yet I can't get it to work at all in my project...
Edit (Solved?): I think I figured out the problem.
I don't know exactly the correct terminology to use for this.. but basically what seems to be happening (for me at least) is that if I attempt to rely on the multiple transitions from the Entry node when the specific statemachine has been entered automatically, it directly selects the default animation and ignores the conditions on the Entry node. However, if you enter a sub-statemachine using a transition (up or down), it works fine. I'm not sure if this makes sense, but it seems to be working for me.
In my current game I wanted to use an animator with multiple sub-statemachines for each stance (weapon type) a player can use. I have an int parameter for the stance and I want to be able to switch between them. Originally I tried to use the conditional transitions from the Entry node to choose which stance to enter and then I'd use the Exit node on each of my stances below when the stance changes so it'd go back to the Entry.
This did not work since whenever you first start your animator up OR whenever you exit up into the top layer using the Exit node, it jumps DIRECTLY to the default state instead of analyzing the conditions on the Entry node.
However, if you instead use transitions targeting the layer above directly (less clean since it can't be as reusable.. but for my purposes it's fine), it will correctly target the next stance because it will hit the Entry Node correctly. I still have an issue with the INITIAL start up. It still goes directly to the default. To fix that, I'm going to set the default state to something in a sub node of some T-Pose-esk stance that will immediately jump back out to the base layer. This might cause a slight character flicker when a character is first created, but it's a decent work around for now.
TL;DR I'm almost certain that this is a bug. The entry node is skipped/ignored and the animator jumps DIRECTLY to the default state UNLESS you are ENTERING the state machine from another state machine. It's possible that this is the intended behavior, but it seems strange. At the very least, I'd like to have an option to change the behavior.
Answer by riseriyo · Dec 14, 2016 at 03:21 PM
Using Unity 5.5. You can change the default transition for the Entry State by right-clicking on Entry and choosing/highlighting, Set StateMachine Default State. Then drag the arrow-line to the State that you want as the new Default.
BTW, I'm using a Mac so if you are a Windows user or a Linux user, use the commands that are equivalent. I don't know them off the top of my head.
Hope this helps.
Answer by IgorAherne · Feb 24, 2017 at 11:18 PM
Use a StateMachineBehavior, and OnStateMachineEnter()
inside of it to CrossFade()
into the needed state. Otherwise a default one will be chosen
Your answer
Follow this Question
Related Questions
Animator dont transition to self or any sub state 2 Answers
Identifying a transition to self in StateMachineBehaviour 0 Answers
how to make multiple transition from one state? 1 Answer
How to make a transition animation, intermediate animation between two main states 0 Answers
Animator set of states 1 Answer