Skip to content

Commit 2a68293

Browse files
fix: NetworkVariable warnings on player spawns [MTT-7161] (#870)
* netvar instantiation pre-spawn * changelog addition
1 parent 2a4903b commit 2a68293

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Assets/Scripts/Gameplay/GameState/ServerBossRoomState.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ void SpawnPlayer(ulong clientId, bool lateJoin)
204204
}
205205
}
206206

207-
networkAvatarGuidState.AvatarGuid.Value =
208-
persistentPlayer.NetworkAvatarGuidState.AvatarGuid.Value;
207+
// instantiate new NetworkVariables with a default value to ensure they're ready for use on OnNetworkSpawn
208+
networkAvatarGuidState.AvatarGuid = new NetworkVariable<NetworkGuid>(persistentPlayer.NetworkAvatarGuidState.AvatarGuid.Value);
209209

210210
// pass name from persistent player to avatar
211211
if (newPlayer.TryGetComponent(out NetworkNameState networkNameState))
212212
{
213-
networkNameState.Name.Value = persistentPlayer.NetworkNameState.Name.Value;
213+
networkNameState.Name = new NetworkVariable<FixedPlayerName>(persistentPlayer.NetworkNameState.Name.Value);
214214
}
215215

216216
// spawn players characters with destroyWithScene = true

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66

77
Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).
88

9+
## [unreleased] - yyyy-mm-dd
10+
11+
### Fixed
12+
* Fixed NetworkVariable warnings that would be logged when a player was spawned (#863) For a player, certain NetworkVariable values were previously modified before the player's NetworkObject was spawned, resulting in warnings. Now, the NetworkVariable itself is instantiated on the server pre-spawn, such that it is instantiated with the new default value, ensuring the new default value is ready to be read on subsequent OnNetworkSpawn methods for said NetworkObject.
13+
914
## [2.3.0] - 2023-09-07
1015

1116
### Changed

0 commit comments

Comments
 (0)