Brent Allen
1 min readAug 16, 2016

--

I think the main issue here is that you have attempted to create two instances of a singleton and expected them to be two separate instances. A Singleton, at least THIS Singleton, will only return the first instance of itself created; a perfectly acceptable implementation. I have also seen them return the last instance created and discard the first, but that would not make sense here. I’m getting off topic.

The point is that both variables are pointing to the same object, and that is how it should be. That’s how you wrote it. The mistake was extending three classes off of a Singleton class and trying to use them as independent instances. Only one instance of EventDispatcher can exist, and the first one wins. Even if the new instance is a different sub-class, the Singleton code exists in the base class, so only the first instance of that base class will ever be returned. Technically, I believe the instance of the next class will be created, but never returned, so you just won’t have a handle on it. So you could never access any of the other classes after creating the first instance.

If you want a single instance of each class, a better implementation would be to have the Singleton code exist in the final child classes. That way, you could have the base functionality of the EventDispatcher, but still only ever have one PlayerController, for example.

--

--