Quantcast
Channel: Questions in topic: "dontdestroyonload"
Viewing all articles
Browse latest Browse all 416

Restoring Static Variables after DontDestroyOnLoad

$
0
0
Hello everyone! Since the day I realised I'd have to learn using DontDestroyOnLoad() I knew I'd mess up a lot of things. It seems to be one of the hardest Unity Scripting topics for me =( So I have an object Alpha with multiple children in a scene 0 with other objects connected to Alpha via script references. Alpha has DontDestroyOnLoad check and also destroys duplicates in case scene 0 is reloaded in playmode more than once. Every time I go to scene 1 and back to scene 0 I have all the objects on their places, but objects other than Alpha lose every reference to Alpha and his children. It is caused by the fact that newly created Alpha that belonged to reloaded scene 0 got destroyed. So I decided to change the script to opposite, destroying the old Alpha on reload. The result was the opposite but still more preferable. After reloading scene 0 again all objects were on their places and all the references were completely fine. The problem is that the script attached to Alpha has static variables that become null for the reloaded Alpha if I destroy the old one. Is there a way to restore those variables and keep the references untouched?

Viewing all articles
Browse latest Browse all 416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>