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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Animator SetFloat doesn't work

Discussion in 'Animation' started by Pierre-Marie, Feb 16, 2023.

  1. Pierre-Marie

    Pierre-Marie

    Joined:
    Aug 3, 2015
    Posts:
    47
    I i'm trying to set a float of the animator depending of a [SerializeField].

    I use the Animator.SetFloat() which doesn't seem to work properly.

    There is the code :

    Code (CSharp):
    1. Debug.Log("awake : " + anim.GetFloat("WeaponEquippedID").ToString() + " / " + WeaponTypeId.ToString()) ;
    2.         if (anim != null && anim.GetFloat("WeaponEquippedID") != WeaponTypeId)
    3.         {
    4.             Debug.Log("awake 1: " + anim.GetFloat("WeaponEquippedID").ToString() + " / " + WeaponTypeId.ToString());
    5.             anim.SetFloat("WeaponEquippedID", WeaponTypeId);
    6.         }
    7.         Debug.Log("awake 2: " + anim.GetFloat("WeaponEquippedID").ToString());
    The Console :
    upload_2023-2-16_17-6-33.png

    The animator Parameter:
    upload_2023-2-16_17-7-4.png

    There is no Script called "animator" in the solution.
    The script which try to SetFlaot is on the same GameObject that the animator.

    Any Idea of the problem?
    Thanks for your help.
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Are you sure you are referencing the correct Animator instance? Also, I'm not sure what you mean with that 'no Script called "Animator" in the solution.' ?

    Have you tried with a simple test scene/setup, where you don't have any extra stuff. It might be that you have an issue somewhere in your Animator state machine or such that causes this issue.