Service manager lifetime and ownership in Unreal; best practice.

ZStaSmith
Thu, 17 Feb 2022 18:24:50 +0000
C++

We are currently using a GameInstanceSubsystem to manage the lifetime and accessibility of a C++ service management class instance (read: shared_ptr object) from a pure C++ library. This binds the lifetime of the object to that of the GameInstanceSubsystem. We are also taking advantage of getting the subsystem via a game instance’s GetSubsystem, so that we get that sort of singleton, global, access of that subsystem that own’s our object.
We would like to move the lifetime of the GameInstanceSubsystem’s object, our instance of our class, to an earlier initialization.

Our new solution is to, instead, is to inherit directly from the UObject class, then this allows us to instantiate that UObject anywhere, even dynamically in blueprints.

But I was wondering if there is a more elegant way to do this?

3 posts - 2 participants