Should be pretty straightforward, right?
An object I’m using for settings has this…
function Start () {
}
function Awake () {
DontDestroyOnLoad (gameObject.transform);
}
I’ve looked through about a hundred topics, questions, scripting API, Script Reference, etc etc etc…
I have yet to find any suggestion on any different way to write that, or any indication I’m doing it wrong, and yet the object is apparently incapable of surviving the level load.
Thoughts?
The documentation says, “If the object is a component or game object then its entire transform hierarchy will not be destroyed either.” So in my opinion your code is valid. Maybe you should try
function Start () {
}
function Awake () {
DontDestroyOnLoad (gameObject);
}
And also when do you load the new scene, I mean are you sure that the Awake function is called before the object is destroyed?
How would I go about that?
I would do it like this
function Start () {
}
function Awake () {
DontDestroyOnLoad (gameObject);
Debug.Log("Object is marked");
}
If you use monodevelop, you can also use the debugger.
Yeah… that didn’t actually do anything so I’m assuming there’s something more fundamental I’m doing wrong.
For Start() & Awake() (& others) your script must be derived from Monobehavior, is it?