I want to create a manager (basically a singleton but without using the singleton pattern) and I want it to be accessible from blueprint. I’m trying to figure out the correct way to do this with Unreal. My first thought is to have the manager inherit from UObject and then make it a default created property of my game mode. Would that be correct or is there a better way to deal with managers and singletons?
Can you be more specific? It doesn’t look like that’s meant to be inherited, so there must be something I’m missing.
You can find guides on GameInstance usage all over the internet.
Epic also introduced a “Subsystem” environment:
I had already searched for more information about GameInstance before replying and I wasn’t able to find anything relevant to C++ (other than the API reference). Everything I could find was either guides for using it in blueprint or questions from other people on how to access the instance from code (with unsatisfactory answers). Although now reading through this subsystems doc, it does refer to deriving from UGameInstance, so I was clearly wrong about its intended usage.
For anyone reading this in the future, it looks like you want to derive from UGameInstance and then you’ll need to update your project settings to point at your game instance (it’s under Mpas & Modes). To be clear, though, there is exactly one game instance, meaning that you are not creating a new game instance class for each manager but rather a single one for your game. So, to answer my original question, I believe the correct solution for adding new managers is to create your own game instance and then use subsystems.