Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

unet5.1 anim Trigger parameter/ how do I use NetworkAnimator.SetTrigger() ??

Discussion in 'UNet' started by CaoMengde777, Aug 30, 2015.

  1. CaoMengde777

    CaoMengde777

    Joined:
    Nov 5, 2013
    Posts:
    813
    okay, so all my animations work over the network, Except my jump animation, it uses a trigger param.
    - a NetworkAnimator component on the character
    - a script with NetworkAnimator.SetParameterAutoSend(0, true) // for each param, has it.
    - player input script calls animations Animator.SetFloat() , Animator.SetInt(), Animator.SetTrigger

    ...all works except jump... (character moves, anim doesnt play)
    so i look in the docs and i find NetworkAnimator.SetTrigger() .. and i try to use it. and it doesnt work.. :(

    from the player Input Controller script : (relevant parts)
    Code (CSharp):
    1. // == animation vars ==
    2.     private Animator anim;
    3.     [HideInInspector] public int jumpHash;
    4.     private Player_NetworkAnimation netAnimScript;
    5.  
    6. void Awake ()
    7.     {
    8.         jumpHash = Animator.StringToHash ("jumpTrigger");
    9.     }
    10. void Start ()
    11.     {
    12.         anim = GetComponent<Animator>()
    13.     }
    14.  
    15. Update()
    16. {
    17. ... ... ...
    18. //=== ----- Jump ----- ===          
    19.                 if (InputManager.GetButtonDown("Jump") && sprintFuel >= sprintFuelMin && stanceFlag == 0)
    20.                 {
    21.                     sprintFuel -= jumpSFuelDepletion;
    22.                     moveDirection.y = jumpHeight;
    23.              
    24.                     anim.SetTrigger (jumpHash);
    25.                     netAnimScript.NetCharacterJump();
    26.                 }
    27.             }
    28. }    

    from another script attached to the player character GO that handles Player_NetworkAnimation.cs:
    Code (CSharp):
    1.  
    2. NetworkAnimator netAnimator;
    3.  
    4. public void NetCharacterJump()
    5.     {
    6.         if(isLocalPlayer)
    7.         {
    8.             netAnimator.SetTrigger("jumpTrigger");
    9.         }
    10.     }
    .. ive tried it with and without the if(isLocalPlayer)

    NetworkAnimator.SetTrigger()
    asks for either the name of the anim param. OR the anim param.s hash ID
    .. i gave it the name that i have set up in the Animator window.. is that right?
    and.. the hashID how do i find that out? .. uh, in my PlayerInputController.cs i have
    the hashes made with Animator.StringToHash and i can see it in the inspector.. is that the right hash ? i dont think so, the docs say "from the animator" .. idk how to get that.
     
    Last edited: Aug 30, 2015
  2. CaoMengde777

    CaoMengde777

    Joined:
    Nov 5, 2013
    Posts:
    813
    derp

    i had to add
    Code (CSharp):
    1. netAnimScript = GetComponent<Player_NetworkAnimation>();
    in Start()

    dunno how i missed that lol ..