When a client connects to a server all clients receive all NetworkVariables
See original GitHub issueThanks @mraue for the update. I get your issue now. Please let me update it and re-open as it seems pretty important.
Description
Every time a client connects to a server all NetworkVariable
s on all NetworkObject
s get synced to all clients.
Reproduce Steps
- Create a NetworkObject with a NetworkVariable. Add a log that tracks
OnValueChanged
- Start a server and connect a client
- Connect a second client
- The first and the second client show the
OnValueChanged
log
Actual Outcome
All connected clients receive a NetworkVariable
update.
Expected Outcome
Only the second client connecting should receive the NetworkVariable
data.
Additional Context
During the internal void SendSpawnCallForObject(ulong clientId, NetworkObject networkObject)
for the NetworkObject to spawn, we mark:
networkObject.MarkVariablesDirty(true);
This causes the NetworkVariable to be considered dirty for all clients. As a result, the NetworkVariable gets serialized to all clients.
The difficulty lies with the fact that current Netcode for GameObjects doesn’t have a way to mark dirtiness for some clients only. This will require a bit of refactor.
Issue Analytics
- State:
- Created a year ago
- Comments:15 (13 by maintainers)
Top GitHub Comments
I tested commenting out the line
networkObject.MarkVariablesDirty();
inSendSpawnCallForObject
. While the initial spawning works fine, the spawning triggered by visibility changes is then broken. The objects do not receive the NetworkVariable states.More details can also be found in the Discord conversation here