- Home /
2D animation transitions turn all components visible
I have a 2D character with lots of components. There are a number of animations, but each animation only has a few components visible. My problem is that when transitioning from one animation to another, all components turn on. What I would like is for a smooth transition between animations with only the components from the first animation visible until the second animation starts.
I've tried making the transition between the two animations instantaneous, but then it's not smooth. I tried to write a script to turn components invisible when the trigger for the transition happens, but it won't override the keyframes of the animations.
If anyone has a suggestion on how to achieve this, I would appreciate any ideas.
@Shegon Hello! Were You sucsessful in solving this problem? I've just faced the same trouble with the transitions and unfortunatly I have no idear how to solve the problem(
Hi @oxred. Well, $$anonymous$$inda. I couldn't do anything with the visibility of the components since that's controlled by the keyframes. I didn't control the sorting layer with the keyframes, though. So what I did was make it so that when one animation started to move into another, I made a script push all unused components behind a background layer so they couldn't be seen. Then when the transition finished, the script brought them back to their original sorting layers. I made a variable to keep track of what sorting layer the thing started on. I basically copied the below script and put it on each component.
public class arm_left_front : $$anonymous$$onoBehaviour {
public Animator animator;
public int layer_tracker;
// Use this for initialization
void Start () {
layer_tracker = GetComponent<SpriteRenderer>().sortingOrder;
}
// Update is called once per frame
void Update () {
if (animator.GetBool("place_holder")==true){
GetComponent<SpriteRenderer>().sortingOrder=-25;
}
if (animator.GetBool("place_holder")==false){
GetComponent<SpriteRenderer>().sortingOrder=layer_tracker;
}
}
}
Then I replaced "place_holder" with whatever the animation trigger was. It's probably not the most elegant solution, but it does work. I hope that helps.
Your answer
Follow this Question
Related Questions
2D animation sprite renderer not updating 1 Answer
Animator State Changing but animation changes only after one animation is complete 0 Answers
2D animations transitioning too quickly and looping before finishing 2 Answers
Mecanim animator layers 0 Answers
I cant add transition on unity animator 0 Answers