Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question What's the best way to make a gameobject invisible during an idle animation state?

Discussion in 'Animation' started by TiggyFairy, May 9, 2022.

  1. TiggyFairy


    Dec 22, 2019
    So I've tried making a short animation clip where the gameobject has its mesh turned off to make it invisible so it's not just frozen in the air - but that seems to knock the objects slightly out of position & is causing lag. I've also tried adding this to an idle animation node to no effect. Any ideas what I can do to make them invisible without messing up the animations? RootMotion is enabled, if it makes a difference.

    Code (CSharp):
    1.     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    2.     {
    3.         animator.gameObject.GetComponent<MeshRenderer>().enabled = false;
    4.     }
    6.     //OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    7.     override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    8.     {
    9.         animator.gameObject.GetComponent<MeshRenderer>().enabled = true;
    10.     }