I know there is going to be a simple answer for this one, but I don’t seem to be able to find it for myself.
I’ve just started using Unities event system for the first time and I’ve got it all set up and working just fine.
Except for objects that are already in the project at run time. They throw up a NullReferenceException when they try to subscribe to my Event Manager.
If the object is instantiated during runtime it can call the EventManager no problems, so it must be down to the order of instantiation. The objects are looking for the EventManager before it exists.
I’m assuming there is work around for this, other than instantiating everything during runtime.
A question to ask yourself is… does the EventManager need to be a monobehaviour? Something like that could potentially be a regular or static C# class.
and @spiney199, I’m not overly proud to say that I used a monobehaviour because that’s how a you tube tutorial did it. Now that I stop and think there is no need for it to be one.
The self instantiating singleton class does seem fairly powerful though, especially as my game will (ultimately) continually be navigating between scenes.