❔ Singleton Pattern StackOverflowException
In the attached code, the GameManager is working fine, but InputManager is throwing a StackOverflowException at line 12. Any help or guidance is appreciated.
9 Replies
(It won't even hit the Debug.LogError on line 14)
I understand what's happening but I have no idea how to fix it.
Declare a private
_instance
field and have your Instance
getter and setter get/set the field instead of getting and setting itself.
Your Instance
property checks if Instance
(itself) is null, but that only calls the Instance
getter which you are already inThe private _instance should be static too, yeah?
Correct
Works perfectly! Thank you so much :)
Happy to help! 🙂
The GameManager one can't be fine, that's the same issue
The GameManager wasn't throwing an error because my game logic would hit the InputManager error and break before it could throw the GameManager error. So, yes, you're right, they were both broken.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.