Search Unity

Animated Script Variables do not Update

Discussion in 'Animation' started by jcsopko, Aug 20, 2015.

  1. jcsopko

    jcsopko

    Joined:
    May 14, 2013
    Posts:
    13



    I am trying to use the Properties in the Animation Window to animate a variable within a Script. The gif shows the Property properly updating when the animation is played in the Animation Window, but not when it is played in game.

    I've submitted a report and have provided my project and other relevant links:

    Anyone have similar problems or suggestions for a work around? I've also tried using the Animator's Parameters, but for some reason the Animation Window isn't letting me add them to my Animation, which is a different problem.
     

    Attached Files:

  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Thanks for reporting this bug, we will take a look

    You can create animation curve that drive animator parameter in the animation window if your clip is not read only, or in the model importer as additionnal curve. In the model importer you need to give the same name to your curve than the animator parameter's that you want to animate

    animatedparameter.png
     
  3. jcsopko

    jcsopko

    Joined:
    May 14, 2013
    Posts:
    13
    I've also tried using an animator parameter, however it is showing as missing as shown below:



    Also in the image it can be seen that retrieving the hash for the animator gives me an ID, but claims that it does not exist retrieving it in script.

    I'm using animator.GetFloat(animator.parameters[0].GetHashCode()).

    Should I report another bug as it is a separate occasion? Don't want to unnecessarily bloat your incident reports.
     
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
  5. jcsopko

    jcsopko

    Joined:
    May 14, 2013
    Posts:
    13
    Thanks for the quick response!

    It is now finding the animator parameter in the script properly, but now has the same problem as reported initially with Animation Properties. The Animator Parameter reads proper values when playing in the Animation Window, but not during playing, either through the Inspector or while printing out the value to the Console.

    Obligatory GIF:


    If there's anything else I can do let me know, thanks again! <3
     
  6. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Which version are you using? I just did a quick test in 5.2 and this is still working
     
  7. jcsopko

    jcsopko

    Joined:
    May 14, 2013
    Posts:
    13
    5.1.2f, I'm downloading the beta now to upgrade and see how it works. I'll report back after it finishes.

    Thanks Mecanim.Dev =D
     
  8. jcsopko

    jcsopko

    Joined:
    May 14, 2013
    Posts:
    13
    Updated to 5.2.01f and the Animator Parameter no longer shows as missing in the Animation Window as a Property, however I am still unable to retrieve its value in script in anyway.

    I currently have these lines of code:

    Code (CSharp):
    1. void Update()
    2.     {
    3.         print(animator.GetFloat(Animator.StringToHash("VelX")));
    4.     }
    5.  
    6. void OnAnimatorMove()
    7.     {
    8.         animVelXParam = animator.GetFloat(Animator.StringToHash("VelX"));
    9.     }
    GIF:



    EDIT: So by placing the key with Mouse Click and Drag instead of typing in the value, I have it outputting values to the Inspector and Console now, but they aren't the right ones...really bizarre behavior. I can provide a GIF or Project of that behavior if necessary.

    EDITEDIT:
    GIF with Mouse Click + Drag:
     
    Last edited: Aug 20, 2015
  9. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Yes please log a bug with your project showing this issue.
     
  10. jcsopko

    jcsopko

    Joined:
    May 14, 2013
    Posts:
    13
    Submitted, if there's anything else I can do to provide you guys with more information to pinpoint it let me know. There's a variety of methods and different weird behaviors I can repro and take videos if needed.

    Bug Link: https://fogbugz.unity3d.com/default.asp?721645_cvvuof2571rec4e8

    Thanks again and good luck!
     
  11. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Thanks, the bug is been investigated