Skip to content
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

fix: networkvariablebase not being reinitialized if networkobject persists between sessions #3181

Draft
wants to merge 9 commits into
base: develop-2.0.0
Choose a base branch
from

Conversation

NoelStephensUnity
Copy link
Collaborator

This PR resolves the issue where a NetworkObject instance with a NetworkBehaviour that includes one or more NetworkVariableBase derived class properties persists between network sessions is not having its NetworkVariableBase.Initialize method invoked again when spawned again. This resulted in clients not being updated to changes in the NetworkVariableBase derived class properties for a period of time equal to the duration of the last spawned time frame from its previous network session.

MTTB-881

Changelog

  • Fixed: Issue where NetworkVariableBase derived classes were not being re-initialized if the associated NetworkObject instance was not destroyed and respawned.

Testing and Documentation

  • Includes integration tests (WIP).
  • No documentation changes or additions were necessary.

This will "re-initialize" NetworkVariableBase derived classes when the instance is not destroyed and repurposed.
adding changelog entry
Adding PR number to changelog entry
? This test needs more comments.
…einitialized-if-networkobject-persists-between-sessions
Changing the approach to this fix while also cleaning up the initialize process so it can be invoked when the derived class is not yet fully spawned (or just recently instantiated) without potentially assigning the wrong NetworkManager instance. It is being invoked multiple times anyway, so this just gradually initializes all of the required elements until it is finally considered "initialized".
This also prevents OnInitialize from being invoked multiple times during this process and OnInitialize is only invoked as a last step to being considered "initialized".

Added a Deinitialize step to NetworkVariableBase when despawning a NetworkObject where the initialized status is reset. This allows for the next spawning of the NetworkObject (if in-scene placed or pooled) to run through the initialization process.
reverting the changes to WhenServerChangesSmoothValue_ValuesAreLerped as the recent update resolves the issue from the previous fix.
Removing exception.
Adjusting when we update the last time.
Logging warning if log level is developer and there is no NetworkTimeSystem.
remove the try catch because evidently it is the only way we can catch certain exceptions during unit testing when duplicating the value (i.e. serializing).
@michalChrobot michalChrobot added stat:awaiting triage Status - Awaiting triage from the Netcode team. port:1.x-needed This issue needs to be ported to 1.X branch and removed type:backport-release-1.0.0 labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
port:1.x-needed This issue needs to be ported to 1.X branch stat:awaiting triage Status - Awaiting triage from the Netcode team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants