Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Activation of mesh render in animation does not work

Discussion in 'Animation' started by Kronus, Nov 17, 2023.

  1. Kronus


    Oct 30, 2021
    Hi all! I want to use Animation to enable and disable the Mesh Renderer component after some time, and I want to write the script in Animation through code using AnimationUtility. During the animation playback, for some reason, the Mesh Renderer activation point is only highlighted in blue, but the component itself is not activated, and for some reason the Property itself also has no checkmarks during the animation playback. How to solve this problem?

    Here is my code and screenshots of the problem:

    Code (CSharp):
    1. void toDoAnimation(GameObject frame, AnimationClip animationClip, int currentFrame)
    2. {
    3.     Animator animator = frame.GetComponent<Animator>();
    4.     if (animator == null)
    5.     {
    6.         animator = frame.AddComponent<Animator>();
    7.     }
    9.     EditorCurveBinding curveBinding = new EditorCurveBinding();
    10.     curveBinding.type = typeof(MeshRenderer);
    11.     curveBinding.path = GetGameObjectPath(frame.transform);
    12.     curveBinding.propertyName = "m_Enabled";
    14.     AnimationCurve curve = new AnimationCurve();
    15.     curve.AddKey(1.0f, 1.0f);
    16.     curve.AddKey(currentFrame / animationClip.frameRate, 1.0f);
    18.     AnimationUtility.SetEditorCurve(animationClip, curveBinding, curve);
    19. }
    Снимок экрана 2023-11-17 232554.png Снимок экрана 2023-11-17 232607.png
  2. Kronus


    Oct 30, 2021
    After spending 2 days I finally fixed it. I just didn't create the Property path correctly. I just deleted it "curveBinding.path = GetGameObjectPath(frame.transform);"
    Last edited: Nov 18, 2023