Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Writing a NetworkObject that had been despawned sent its PrefabId, so the
reader resolved the reference to the prefab asset instead of null. This
affected RPC parameters, SyncVars, broadcasts and any custom serializer,
through WriteNetworkObject, WriteNetworkBehaviour, WriteGameObject and
WriteTransform.
The receiver ends up holding the prefab asset where it should have
null, so code acting on that reference could end up operating on the prefab instead of an instance. This is easy to hit: despawn an object and pass it to an RPC or SyncVar in the same frame. Pooled objects are affected for as long as a stale reference is held, not just for that frame.Cause
Despawning sets IsDeinitializing, so IsSpawned becomes false while the
C# reference stays non-null. WriteNetworkObject took its "not spawned"
branch, which exists for prefab-template references, and wrote PrefabId.
Fix
NetworkManager is assigned when a NetworkObject initializes and is never
cleared by ResetState. If it is set, the object was spawned at some point
and is no longer valid, so a null reference is written instead. Prefab
assets and never-spawned instances still write their PrefabId.
Behavior change
A recycled pooled instance that has been fetched from
the pool but not yet spawned now serializes as null instead of the
prefab.