Skip to content

Clearing NetworkList Offline #2969

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

Closed
KreutzerCode opened this issue Jul 8, 2024 · 7 comments
Closed

Clearing NetworkList Offline #2969

KreutzerCode opened this issue Jul 8, 2024 · 7 comments
Labels
type:support Questions or other support

Comments

@KreutzerCode
Copy link

Setup:
Unity 2023.2.7f1
Netcode for Gameobjects v1.8.1

Question:
Hi, I have a simple but confusing question about NetworkList variables.
When I was testing the state of my clients when they connect and disconnect a game, I noticed something strange regarading the data of the NetworkList.

Steps:

  1. the client connects to a game
  2. the host of that game writes some data to the network list
  3. the client disconnects from the game (now offline)

Now the client can still read the data of the old game session from the NetworkList, but it cannot clear the list because of missing permissions and remains stuck with the old session data. The data is only overwritten when the client joins a new session as a client or host.

I have looked at the documentation and implementation of Networklist and have come to the conclusion that this is an intended behaviour. My question is WHY, and how is it intended to get rid of the old session data when offline?

TLDR: The client cannot delete old data from the NetworkList when the connection to a session is terminated.

If I have overlooked something or am still missing important information to understand my question, please let me know. Many thanks in advance!

@KreutzerCode KreutzerCode added stat:awaiting-triage Status - Awaiting triage from the Netcode team. type:support Questions or other support labels Jul 8, 2024
@NoelStephensUnity
Copy link
Collaborator

Hi @KreutzerCode,

My assumption is that the NetworkList is on an in-scene placed NetworkObject since dynamically spawned NetworkObjects get automatically destroyed on the client side?

@NoelStephensUnity NoelStephensUnity added the stat:awaiting-response Awaiting response from author. This label should be added manually. label Jul 22, 2024
@KreutzerCode
Copy link
Author

Hi @NoelStephensUnity

That is correct. It is a “GameManager” game object that is loaded in the first scene of the game, this game object is DontDestroyOnLoad and accompanies the player throughout the game.

@KreutzerCode
Copy link
Author

@NoelStephensUnity is this part of the answer to my question? If so, I would appreciate a brief explanation of the process ^^

@NoelStephensUnity
Copy link
Collaborator

@KreutzerCode
😸
Sorry about that... I was looking into the adjustments needed for this and ran into the divide between in-scene placed and dynamically spawned...which was (if memory serves) part of the reason to not provide this functionality due to the distinct differences between in-scene placed and dynamically spawned objects.

Since this kind of functionality would only apply to in-scene placed NetworkObjects and any pooled NetworkObjects used for dynamically spawning, I need to run through a review process for this kind of change.

My recommendation (for now) would be to use the "hybrid approach using dynamic spawning of a non-pooled network prefab" where your in-scene placed NetworkObject is (if not already) converted to a network prefab and then in place of the in-scene placed GameManager you have a "GameManagerSpawner" that dynamically spawns the GameManager.

This way when the game session completely ends there are no remaining artifacts (if that is an issue for your project).

If not... and you were truly curious as to why you can't do this... it was a decision made like 2+ years ago that I think deserves to be revisited but (unfortunately) it will be awhile as it does require an internal review process and then scheduling for this.

@KreutzerCode
Copy link
Author

@NoelStephensUnity
Okey thanks for the detailed description and the solution approach! I will take this condition into account next time. For my project it is already quite unfavourable to destroy the complete object when i want to get rid of the networklist content. But I already have a dirty hack around it.

Just for my interest, will this behaviour be changed in the future as you described?

The issue can therefore be closed. Thanks again!

@michalChrobot michalChrobot removed the stat:awaiting-response Awaiting response from author. This label should be added manually. label Jan 17, 2025
@michalChrobot michalChrobot added stat:reply-needed Awaiting reply from Unity account and removed stat:awaiting-triage Status - Awaiting triage from the Netcode team. labels Apr 1, 2025
@NoelStephensUnity
Copy link
Collaborator

@KreutzerCode
Following up on this issue you are having with clearing the list of the in-scene placed NetworkObjects with the NetworkList that contians a previous session's data. We are looking at the possibility of allowing modifications to NetworkVariableBase derived classes when not spawned.

Until we get to that type of update, have you thought about doing the following:

  • Clearing the NetworkList when it is despawned?
    • If the in-scene placed NetworkObject is always spawned while in-game then you just need to clear it when despawned.
    • If you need to spawn/despawn that in-scene placed NetworkObject, then in OnNetworkDespawn check for the NetworkManager.ShutdownInProgress property to be true before clearing it.
  • Placing the in-scene placed NetworkObject in a separate scene that is additively loaded by the host when you start a session.
    • Provides you with the ability to just start with a fresh instance per session.
  • Of course, there is always the option of having the host just clear the list when first spawned.

Just letting you know we are tracking this particular issues related to the root issue of not being able to modify NetworkObjectBase derived classes when offline. Since there are several ways to handle this issue (described above and my initial response), it is not in the top of our priority queue but we still have the root cause of this issue in our crosshairs. 👍

@github-actions github-actions bot added stat:awaiting-response Awaiting response from author. This label should be added manually. and removed stat:reply-needed Awaiting reply from Unity account labels Apr 4, 2025
@michalChrobot michalChrobot removed the stat:awaiting-response Awaiting response from author. This label should be added manually. label Apr 10, 2025
@NoelStephensUnity
Copy link
Collaborator

This is already being tracked in #2539. Closing it as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:support Questions or other support
Projects
None yet
Development

No branches or pull requests

3 participants