Host & Client user input moving both Player prefabs at the same time

I have a player controller attached to the Player prefab - along with the NGO components

Network Object Client Network Transform Network Animator

In the Network Manager I have the Player prefab added so that the host & clients will spawn when joining.

The issue I have is that the user input from client & host is controlling both prefabs on screen at the same time.

On the player controller script I have the line if (!IsOwner) return; at the start of the Update() before any movement is called

Any help much appreciated.

See the attached video for the issue

Post your code too. And some info on the prefab setup.
Somehow you are applying input to both character controllers, that much is clear.

thanks for the reply!

The Player Prefab is setup as follows:

  • Player (Has the Network Object & Client Network Transform components)

  • Controller (Has the PlayerController script attached to it)

  • Model (Has the Owner Network Animator component with the Animator applied)

This is the PlayerController update function:

void Update()
    {
        if(!IsOwner) return;
     
        if (!rigidbody || !animator) return;

        currentVelocity = rigidbody.velocity;

        GetAxisHistory();

        GetTargetHeading();

        GetLocomotionState();

        GetTurnSpeed();

        if (currentAnimationStates.HasFlag(AnimationPlayerStates.Pivoting))
        {
            SetTurnParams();
        }
        else if (TurnTriggerIsSet())
        {
            SetVelocityToCurrent();
        }
        else
        {
            TurnCheck();

            SetLocomotionVelocity();
        }
    }

I am getting these warning messages when the Host & Client Spawn into the scene

  • Model (1) is disabled! Netcode for GameObjects does not support disabled NetworkBehaviours! The OwnerNetworkAnimator component was skipped during ownership assignment!

  • Model (1) is disabled! Netcode for GameObjects does not support spawning disabled NetworkBehaviours! The OwnerNetworkAnimator component was skipped during spawn!

EDIT:
I am using the new Input System

I suppose it could be this but not sure:

if(!IsOwner) return;

If you have server-authoritative movement (the default) then the owner might be the server for all player objects. I’m not sure and can’t confirm if that holds true for player objects. Try logging NetworkBehaviour.IsOwnedByServer to see if server owns those.

If you need movement client-authoritative you can get that script from Boss Room example or take mine, it lets you change authoritah at runtime. Sorry about the name, big South Park fan. :slight_smile:

Also, you could simply choose to Destroy() or enabled=false the character controller script in OnNetworkSpawn if it isn’t the owner object and skip the check in Update. That way you’d also see in the Inspector who got the controller and who doesn’t and you don’t have to add even more IsOwner checks anywhere (ie OnDisable, LateUpdate, and so on).

So I have the soloution working in another smaller projects using

public override void OnNetworkSpawn()
    {
        if (!IsLocalPlayer) enabled = false;
    }

This is turning off the player controller script for the player that is not local.
This works fine in the prototype project but I cant get it to work the same way in my main project
The script is disabling as expected but the 2 players are still being controlled on both the Host & Client from both inputs.

In the editor everything is showing as expected for both players (IsHost / IsLocalPlayer / Script disabled)

Could this be an issue with the new input system? Do I need to have a control scheme for Player1 & Player2?

New input system is fine, and you don’t need control scheme for player1 & player2. That wouldn’t make any sense unless you’re trying to do split-screen co-op game.

So it was because I was using 2 instances on the same machine - the input was being read by both. I was able to get the outcome when I played a host & client across 2 different machines using gamepads. Each gamepad controlled their own player. Problem solved!

1 Like