How to handle Systems / Controllers in UE4?

Hi everyone,

we are developing a kind of CAD application using UE4 and I’m constantly facing this annoying problem: let’s say I have my main controller (eg. entry point of my custom application) where I bind inputs to handlers, instantiate uobjects, spawn default actors… many of these uobjects are systems / subcontrollers / services that will get called everywhere in my codebase (objects factories, network services, etc.).

I was thinking about creating some kind of resolver much like in a dependency injection scenario where you configure your container by registering types. The actual implementation would ideally require a TMap[FString, UObject*] where all the instances are stored. But this approach leaks memory as uobjects in tmaps get garbage collected.

How would you manage instances of these kind of objects in such application? Right now I have an UPROPERTY for each system / service in my main controller, along with getters, and each spawned actor has a reference to the main controller… I feel like this implementation doesn’t scale well should we start adding more and more systems to it.

Have a nice day,

I think it’s fine as lot of engine code do what are you doing, there is centralized main UEnigne class which contains references to lot of other engine subsystems

You can also make some static pointer to it with TWeakObjectPtr, or just make singleton access point in the module class same lot of engine modules have with Get() function:

Also think if you really need to use UObjects for you system if you doing C++ only, some API are sitting in module class like HTTP i showed above. Module classes can be also accessed via module manager

Thank you for your insight. Modules are indeed what I was looking for!