Skip to content

fix: NetworkVariable warnings on player spawns [MTT-7161] #870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Assets/Scripts/Gameplay/GameState/ServerBossRoomState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ void SpawnPlayer(ulong clientId, bool lateJoin)
}
}

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

// pass name from persistent player to avatar
if (newPlayer.TryGetComponent(out NetworkNameState networkNameState))
{
networkNameState.Name.Value = persistentPlayer.NetworkNameState.Name.Value;
networkNameState.Name = new NetworkVariable<FixedPlayerName>(persistentPlayer.NetworkNameState.Name.Value);
}

// spawn players characters with destroyWithScene = true
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

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

## [unreleased] - yyyy-mm-dd

### Fixed
* 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.

## [2.3.0] - 2023-09-07

### Changed
Expand Down