I must be fundamentally not understanding DontDestroyOnLoad. I have a Splash Screen on my app followed by a Main Menu Scene followed by several menus.
Since all the menus share common objects, I called DontDestroyOnLoad on several of these objects in the Main Menu Scene- GUITexts, Lights, a Plane, a 3D character and what have you.
Its working fine as long as I keep going forward through the menus. Its even working fine while going back through the menus. But when I come back to the Main Menu, all the objects that I called DontDestroyOnLoad are duplicated.
If I understand you right, before calling DontDestroyOnLoad in an object’s Awake function, I have to check if that if an object of this type exists already.
I have several GUI Text objects on screen, so wouldn’t checking objects with same name be correct here.
should have better formulated it: check if more than 1 is present by FindObjectsOfType
if more than one is present, then destroy the one which the component is in