I have an 'awake' function which sets up an instance, like so:
This works fine, no problems.
However if I change a script during run time and unity does its recompilation 'Awake' isn't called on 'MySingleton' and another script from its normal update routine attempts to access it causing a null reference exception...
Any idea how I could make sure 'awake' is called straight after a script is recompiled or does Unity not provide a way to handle this?
asked May 16 '12 at 11:57 AM
Dynamic compilation isn't really a good idea, but that code is dangerous anyway. You should call an Init function both in get and Awake if the instance is null, that way it's initialize not matter which one is called first.