[Solved] NetworkBehaviour.isLocalPlayer is return false for both the server and the client.

Here I have both cubes selected in the server and the client:

And here’s the relevant code:

    private void Update() {
        InputEvent();
        if (this.selectedObjects.Count > 0) {
            if (this.isLocalPlayer) {
                SetSelectionColor(this.selectedObjects, Color.green);
            }
            else {
                SetSelectionColor(this.selectedObjects, Color.magenta);
            }
        }
    }

If I select one of the cubes in both the server and the client, the selected cube shows up as magenta. It doesn’t matter if I select the cube in the server or in the client, the cubes themselves will always show up as magenta and not green.

The docs mentioned the NetworkBehaviour.isLocalPlayer will return true if the object is represented by the player’s local machine. I am guessing the “local machine” part is referring to the instance of the Unity Player. If it represents the machine I am using, then the cubes should be colored in as green.

This is very confusing. If neither the server nor the client owns the cubes, when who owns it?

Only player objects use isLocalPlayer. are the cubes players?

There is hasAuthority for non-player objects

Yes, the cubes are “players”, in a sense that they should be player-controlled.

And both the server and the clients do not have authority on the cube prefabs auto-spawned in through Network Manager.

I haven’t completely solved this yet.

The only hint so far that I can try is to make the cube game objects react to the player’s inputs by using a mix of [ClientCallback], [SyncVar], and [Command]. It’s not pretty, and it’s very unstable.

If anyone else knows about spawned prefabs with no authorities on both the server and clients, please post here.

It sounds like a bug. Can you post a project that reproduces this?

Hi there,

Would you like me to give you the bug report ID number, or have the project be hosted on GitHub, so you can take it away and test?

I just sent out a bug report, and am currently waiting on the confirmation email, so I can get the ID number.

I rewrote a simpler version in a clean project (with UnityVS) to replicate the bug, and it’s 100% reproducible.

Bug ID Number is in:
718435

Some more testing reveals that isLocalPlayer and hasAuthority toggles to TRUE and FALSE, back and forth, for each Update().

If you constantly let the game run, the Console will keep spitting is and isn’t local player and has authority each respectively. Hm…

When I run that project, everything seems to be working correctly. The white cube is in the same place as the colored, cube, so you cant see the colored one. If you move the white cube (or spawn the players at different locations), you can see the colored cube.

The preview panel in the inspector shows the local player and authority status for objects:

The logs of alternating authority/not-authority are for different objects, not the same object changing state.

Ah, that explains how I’m getting white cubes on both the server and the client. It’s kind of unexpected how there’s no Z-fighting, when both cubes are placed in the same position. And it brought out more questions. Don’t worry, I asked them about this here.

I guess you can close that bug report, seeing how this is resolved.

Also, I never knew you can inspect the Network Information in the Inspector on the cloned cubes.