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

DontDestroyOnLoad duplicates GameObjects

$
0
0
Hello. I have a strange problem with **DontDestroyOnLoad**. I have some kind of map as a starting scene. From there there user can click on certain map-objects and a new level is loaded with **Application.LoadLevel()**. When the level is finished the map is loaded again. I have a prefab for my global data. It is a hierarchy of several GameManagers und DataObjects that are needed in every scene. The hierarchy looks like this in design-time: ![alt text][1] The root GameObject 'GlobalData' has a script attached that calls **DontDestroyOnLoad**: using UnityEngine; using System.Collections; public class GlobalData : MonoBehaviour { void Awake() { DontDestroyOnLoad(this.gameObject); } } As far as I understood the docs all child gameobjects should not be destroyed, too. After starting the game and playing some levels (with jumping back to the map) the hierachy looks like this during runtime: ![alt text][2] Somehow the prefab is added again and again but the manager-objects are missing. [1]: /storage/temp/54720-001.jpg [2]: /storage/temp/54721-003.jpg Another issue is that **DontDestroyOnLoad** does not seem to work in general as when I'm doing some debug prints the **Start** and **Awake** methods of my manager-objects are called for every scene. Has anybody an idea what is going wrong here?

Viewing all articles
Browse latest Browse all 416

Trending Articles



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