when quiting, spawned object become null whereas in-scene objects are not. #3145
Labels
priority:medium
This issue has medium priority and may take some time to be resolved
stat:imported
Status - Issue is tracked internally at Unity
type:bug
Bug Report
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 allnull
.By looking into the source code of
NetworkManager
, it appears thatNetworkManager
also implementedOnApplicationQuit()
in whichShutdownInternal()
is called. So, I changed the script order of my "script_1" or move saving code toApplication.wantsToQuit
, so that in debuging, My saving code is always called before NetworkManager'sOnApplicationQuit()
. However, the reults are all the same(valid spawned object reference become null), and the NetworkManager always has shutdown even before NetworkManager'sOnApplicationQuit()
being called.This only happens to the dynamically spawned object, the referece to the in-scene object remains valid.
Reproduce Steps
Application.wantsToQuit
Actual Outcome
Reference to in-scene object is valid, but to spawned object is
null
inApplication.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
References in
Application.wantsToQuit
Environment
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.
The text was updated successfully, but these errors were encountered: