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

when quiting, spawned object become null whereas in-scene objects are not. #3145

Open
babaq opened this issue Nov 29, 2024 · 0 comments
Open
Labels
stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report

Comments

@babaq
Copy link

babaq commented Nov 29, 2024

Description

I want to save gameobject states before quitting, so when i load a scene and spawned several object(destroyWithScene = true), i cached the references to some objects. Then, when i quit(stop playing in editor), i implement the saving code in OnApplicationQuit() on monobehavior "script_1". But the saved data are all zeros(default), and in debuging, the references to spawned objects are all null.

By looking into the source code of NetworkManager, it appears that NetworkManager also implemented OnApplicationQuit() in which ShutdownInternal() is called. So, I changed the script order of my "script_1" or move saving code to Application.wantsToQuit, so that in debuging, My saving code is always called before NetworkManager's OnApplicationQuit(). However, the reults are all the same(valid spawned object reference become null), and the NetworkManager always has shutdown even before NetworkManager's OnApplicationQuit() being called.

This only happens to the dynamically spawned object, the referece to the in-scene object remains valid.

Reproduce Steps

  1. start a host
  2. load a scene and spawn a network prefab
  3. find and cache the reference to a in-scene object and the spawned object
  4. set debug breakpoint and quit
  5. check the references in Application.wantsToQuit

Actual Outcome

Reference to in-scene object is valid, but to spawned object is null in Application.wantsToQuit

Expected Outcome

The references should be valid and object states can be retrieved in Application.wantsToQuit

Screenshots

References when scene loaded and a object spawned
Image

References in Application.wantsToQuit
Image

Environment

  • OS: [Win10]
  • Unity Version: [6000.0.26f1]
  • Netcode Version: [2.1.1]

Additional Context

Add any other context about the problem here. Logs, code snippets would be useful here but please also consider attaching a minimal Unity project that reproduces the issue.

@babaq babaq added stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report labels Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting triage Status - Awaiting triage from the Netcode team. type:bug Bug Report
Projects
None yet
Development

No branches or pull requests

1 participant