Best place to register a service on startup?

If there is a service, like a TcpListener for example, you want to start at the beginning of a game on a the authority client, where is the best place to begin this service? Should it just be placed on an actor in the scene or is there a better place to put this kind of code?

I have a tendency to initialize stuff in the player controller, during BeginPlay, or in the Level blueprint. I guess it depends on what you need to do.

From https://forums.unrealengine.com/showthread.php?3913-BlueprintImplementableEvent-function-in-a-UBlueprintFunctionLibrary-derived-class&p=25345&viewfull=1#post25345:

Worth considering!

I forgot about the level blueprint, but that sounds like a good candidate as well. I’m just trying to get an idea of what the good practices are in the engine… or is it more “where ever they will fit”.

Neverender,

This is where I have the logic currently and it seems to be working out. I just wanted to see where other people place there types of things.

It depends on what you want the service lifecycle to be, if it has to be started once for the whole execution, once per map loaded, oncer per match, once per player…, and if it has to be replicated or not and/or where is it going to be accesible from. It also depends whether you want some custom behaviour, like different maps doing something different on startup, or all the instances behaving the same.

There is really no “just one” good place.

We are also working on a new framework class called the GameInstance that corresponds to the lifetime of your ‘app’ (it will persist across level transitions, but you will get multiple of them for things like multiplayer PIE sessions). When that comes online, that might be useful for what you are talking about. We hope it will be in 4.3.

Will that be like a replicated GameSingleton?