- Home /
Animation messed up when object deactivates?
Hi everyone, I have a button with animator component and four animations (Disabled, Highlighted, Normal and Pressed). When i press on the button i deactivate the panel containing this button and activate a new panel, what happens is simply the button scaled down on press event, now when i reactivate the pannel containing this button the scale won't return back to normal scale which is Normal animation state!.
I know that problem happens when i deactivate the object containing the animation while it is playing (It won't return to normal state). Does anyone know how to solve this issue, any solution or even hackaround is appreciated.
Thanks all.
check the animations for the 'write defaults' toggle and check it
Actually there some workarounds to this issue like make a script on the animation and implement the initial state in OnDisable() or disable the renderer of the gameObject until animation finishes then disable the gameObject, But i really don't think that it's a good idea to always use this technique to solve the issue, Please suggest any solution if you can.
what does the animator say? is it in the right state (open animator Rosie and select the button)? does the state control the scale?
from my today's experience, every animation controlled value is not even changeable manually so if both your answers are yes, I don't know, I check on it tomorrow :)
Answer by Omar47i · Nov 28, 2016 at 02:08 PM
Ok i think i found a work around, i can't consider it a solution but it did what i want. First to prevent the unexpected animation behaviour i made a coroutine to wait for a specific amount of time before disabling the gameObject containing the animation say .18f seconds to ensure that it doesn't interrupt the transition between states, While it works well if the user tapped quickly on the button within the waiting time (.18f) then the same bad behaviour occurs again, so i solved it using this code:
// to indicate if we currently in an animation
private bool inAnim = false;
public void onPlayButton()
{
if (!inAnim)
{
// disable collider on the button to prevent unexpected behaviour
m_PlayButton.GetComponent<Image>().raycastTarget = false;
inAnim = true;
StartCoroutine(onPlayDelayed());
}
}
private IEnumerator onPlayButtonDelayed()
{
yield return new WaitForSeconds(.18f);
next_UI_Panel.SetActive(true);
current_UI_Panel.SetActive(false);
// enable collider on the button again
m_PlayButton.GetComponent<Image>().raycastTarget = true;
inAnim = false;
}
Hope that help you guys. thanks.