Hi
I’m just starting out with Unity after having spent 14 years doing traditional game development in C / C++ and am finding it a bit odd.
In general, Unity is completely awesome and has vastly exceeded my expectations; but I’ve hit a stumbling block that has got me totally stumped / deeply freaked out.
In all likelihood, I’m just being a muppet and have missed the obvious stuff about this in the docs.
Anyway here’s my basic problem:
I have an object that (for whatever reason) I want to instance and attach as a child of another obejct.
I do this in Start(), which is where the tutorial stuff says to do this sort of thing, but from what I gather this would be fine in Awake() too.
When I run the game in Unity by pressing the “play” button, (as expected) the object gets cloned and attached as a child of the other object fine, it renders, it moves about as expected. So far so froody.
However, when I un-click “play” the cloned object stays there and I have to manually delete it from the hierarchy view.
I had a look at the docs, and it said OnEnable() and OnDisable() were for initialisation and shutdown, so I tried using them and they didn’t get called at all despite the fact the script is clearly initialising and updating :-/
I’ve even tried putting the clean up code for the cloned object into OnApplicationQuit() and that doesn’t get called either.
Argh :shock:
I mean the fundamental interface of any object that’s used for games is that it needs the following functions:
Create() - slow one-off stuff (allocate memory etc.)
Reset() - reset the object’s state to initial state (separated from Create() so operations such as restarting a level are fast)
Update( timestep ) - update function called once per frame
Destroy() - cleans up any system resources allocated by Create
Call me a stickler for details, but I quite like to have explicit control over how I initialise and shutdown objects…
So, is there any “opposite” function to Start()?
Or am I just missing some huge paradigm shift in perspective that is needed for Unity development?
cheers
darbotron