What blueprint event is best to automatically manage LAN multiplayer sessions

Hi community

I am trying to create a configurable LAN networked game that automatically launches the build in server or client mode and auto-connects to the configured server. However, I am not sure in which blueprint event (e.g. BeginPlay) and in which object (e.g. GameMode or GameState or PlayerState or PlayerController) I have to put the server and client logics like “CreateSession” and “FindSessions” to start the multiplayer without any input from the player.

As a (native) C++ developer, I set my personal goal to learn blueprint scripting, but feel free to offer me also a C++ answer if this is a (better) solution.

Full story :
I have already successfully connected clients to a LAN listening server via blueprints through the HUD and with an interaction menu. However, here the player needs to create the session and another player needs to find and join that session.
To automate this, I would like to use config ini-files as these are configurable upfront before launching the game. I might also use arguments to the main, but went for the first option at this point for the ease of use in bigger context.
When starting the game in the editor, you can do this without any code in the launcher (i.e. Net Mode and Number of Players), but I do not know how to detect in blueprint (and where) if this is the server or the client. I need this for additional code I would like to run. In my understanding of the article Setting Up Dedicated Servers, I might also use these arguments on launching, however Shipping Build doesn’t support console and command line arguments. Furthermore, I am still struggling with where to put server specific blueprint logic versus client only.
The last part is the most challenging for me, as I have the impression the BeginPlay event is called multiple times for networked players and for changing levels/maps, making this tricky to just assume its lifecycle throughout networked sessions. In my limited understanding by printing debug for each event, it looks as the following (but I do not fully understand why exactly) : GameMode_OnPostLogin → GameMode_BeginPlay → GameState_BeginPlay → PlayerController_BeginPlay → HUD_BeginPlay → (for each joined player) → PlayerController_BeginPlay → GameMode_OnPostLogin → PlayerController_BeginPlay → HUD_BeginPlay → GameState_BeginPlay

Thank you very much for taking your time to explain me some of the magic :slight_smile:

I am not sure in which blueprint event (e.g. BeginPlay) and in which object (e.g. GameMode or GameState or PlayerState or PlayerController) I have to put the server and client logics like “CreateSession” and “FindSessions”

You are probably looking for a GameInstanceSubsystem