Animation shows for Host only

Hi, I’m trying to add animations to the units, it works for moving and when attacking. Only thing is that the animation works for the host, not the joined player. Even when the joined player unit comes into view on the host screen the unit animation works for the host.

Guess what I’m saying is that both players units animats for the Host, not the joined player.

[ServerCallback]

    private void Update()

    {

        Targetable target = targeter.GetTarget();

        UpdateAnimation();

        if(target != null)

        {

            if((target.transform.position - transform.position).sqrMagnitude > chaseRange * chaseRange)

            {

                agent.SetDestination(target.transform.position);

            }

            else if(agent.hasPath)

            {

                agent.ResetPath();

            }

            return;

        }

        if (!agent.hasPath) {return;}

        if (agent.remainingDistance > agent.stoppingDistance) {return;}

        agent.ResetPath();

    }

    private void UpdateAnimation()

    {

            Vector3 velocity = agent.velocity;

            Vector3 localVelocity = transform.InverseTransformDirection(velocity);

            forwardAmount = localVelocity.z;

            turnAmount = Mathf.Atan2(localVelocity.x, localVelocity.z);

            animator.SetFloat("Move", forwardAmount);

            animator.SetFloat("Turn", turnAmount);

    }

Found the video by the RTS course instructor for the animations, so I have that working now, but I’m also using an AnimatorOverrideController like in the RPG course.

The Host animates the override but the joined player using the old one, I’m not sure where this needs to be put right now I have it in an OnStartSever. At a loss still on how a lot of the server and client stuff works.

    public override void OnStartServer()
    {
        ServerOnUnitSpawned?.Invoke(this);

        health.ServerOnDie += ServerHandleDie;
        AnimationOverride();
    }
private void AnimationOverride()

    {

        var overrideController = animator.runtimeAnimatorController as AnimatorOverrideController;

        if (animatorOverride != null)

        {  

            animator.runtimeAnimatorController = animatorOverride;

        }        

        else if (overrideController != null)

        {

            animator.runtimeAnimatorController = overrideController.runtimeAnimatorController;

        }

    }

My guess would be you need to setup the override Controller on the client and host separately, since they are different instances of the animation controller.

So I have the AnimationOverride() in both the onStart Server and Authority. While the Host seems to work, you can see both players’ override (the bowmen do a shoot animation, not a melee), but for the joined player their override works but the Host uses the old animation (melee attack with an arrow coming from it lol).

In short, the Host sees both players doing the correct animation, but the joined player only sees their own units doing the correct animation. Damage, animation movement still work overall.

So think through what’s happening. The host is overriding itself and all the other clients on the server and the clients are overriding themselves on the client, but not the local version of the other players. So you will probably need to get hold of all the animators you want to override and override them, and do this on the server and client.

So was still at a loss until I looked at all the OnStart overrides and saw the OnStartClient is called for the host and client, so I put the AnimationOverride method in an override OnStartClient.

I don’t know if this will cause a problem in the future by not being called in the server but it works now.

Both host and player see the animation overrides, I hope this is a correct fix.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms