Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k stars 435 forks source link

Auto spawned Player objects spawning on clients when Spawn With Observers is false (NGO 2.0.0 only). #3076

Open ezoray opened 1 month ago

ezoray commented 1 month ago

Description

With the Spawn With Observers flag unticked on the Player prefab Player objects of other clients will spawn on a client, but (correctly) not its own.

NGO 1.11.0 behaves correctly and no Player objects are spawned on clients.

Reproduce Steps

  1. Create Player prefab with Spawn With Observers unticked on the NetworkObject component.
  2. Add prefab to as the Default Player Prefab on the NetworkManager.
  3. Run project as host and have a client connect to it.

Actual Outcome

On client connection the host's Player object spawns on the client, the client's own Player object correctly does not.

Expected Outcome

No Player objects should spawn on the client.

Environment

Additional Context

The code used to test is here, it's currently set to NetworkShow the client's own Player so both host and client's Player objects will be spawning.

NoelStephensUnity commented 1 month ago

Looks like NetworkSpawnManager.AddPlayerObject is the culprit here. I will have a PR up for this fix sometime today/tomorrow and the fix should be in the next NGO v2.0.1 update.