I’m attempting to play an animation from different layers but having some difficulty. I’m trying to play animation transitions in one layer and then go back to the base layer to play an animation after the transition is completed. However, the animation in the base layer isn’t playing. Here’s a sample of the code:
Thanks for the reply. It’s appreciated. The animations work without code as viewed in the Inspector’s Preview of the transition. I’ve attached a screenshot of the Animation previous in the Inspection view as well as the triggers in the Animator Controller.
After switching from Boolean parameters to Trigger, the result was the same. The subsequent animation that is to play, does not. However, when stepping through code, when the triggers are called, execution is immediately returned back to the place that called the function (MyFunc1 in the sample code) rather than completing operation in the coroutine before returning the code that initially invoked the function.
The coroutine in the snippet above does not have a yield. I understand perhaps you shortened it for posting? Without a yield the code would not even compile.
Otherwise there’s an animator obtained from m_Player1.GetComponent<T>() and one passed in.
Generally you want to avoid using GetComponent() except where there is no other choice.
Are those the same animator? Are you sure m_Player1 is actually the player IN your scene and not a reference to the prefab? If it’s the prefab, all bets are off as that’s just the file on disk.
Simply Instantiate-ing a Prefab does nothing to the prefab. It’s still a file on disk, unchanged. See below.
Here’s some more about names like m_Player1 and the problems the might cause:
Instancing and prefabs in Unity and naming your variables:
If you name your public / serialized fields (variables) as simply “thing” then you set yourself up for confusion.
If something is a prefab, name it that, such as public GameObject ThingPrefab; and only drag prefabs into it. Prefabs are “dead things (assets on disk) waiting to be Instantiated.”
If something is already in the scene or you Instantiate<T>(); it in code, then store the result in a properly-named variable such as private GameObject ThingInstance;
Naming is hard… name things WELL to reduce your own confusion and wasted time.
The code wouldn’t compile if the yield wasn’t included. So, yes, it was left out for brevity. As mentioned in the initial post, the transitions work fine, so the prefabs that are instantiated for the GameObjects, m_Player1 and m_Player2 are fine, as well. All operations for these objects work except for the animation that is called after the coroutine. That is, if the coroutine is skipped or not called, the animations that follows the coroutine runs fine in the code.
Also, we’re unable to play the same transitions, consecutively. That is, after the 1st call to animation transition in another layer, all subsequent calls will not play. It appears that the maybe the parameters are resetting or there maybe some interference with the layer? Could this be related to initial issue or question in this post?
It appears that you really have nothing to add, so gonna have to ignore your responses, henceforth. There’s nothing edifying in them, so it makes them insipid and not worth reading.
We’re able to play animations in the Base Layer after playing animation transitions in other layers by syncing the animation transition or layers w/ the Base Layer (see attached screenshot). However, the animation transitions now play too fast. We’ve tried slowing down the speed of the animation clips in each transition but no avail. Also, tried Addictive Blending, so that the speed settings would not be overridden and that didn’t work, either.