Best Practices for Updating GameMode Flag from Widget

Hello
I’m seeking advice on the correct methodology for updating a flag in my ALobbyGameMode from a widget, particularly when dealing with scenarios like manual session creation. Here’s a detailed breakdown:

Context:

Within Unreal Engine, I’ve implemented a bGameLogicActive flag in my ALobbyGameMode that dictates whether specific game logic, especially PostLogin functionality, should be active.
*I need to dynamically adjust this flag from my UGameMainMenu widget, especially when creating a session manually.

Current Implementation:

In UGameMainMenu, I have a method called ToggleGameLogicActive(bool bActive) tasked with toggling the value of bGameLogicActive in ALobbyGameMode.

void UGameMainMenu::ToggleGameLogicActive(bool bActive)
{
    ALobbyGameMode* LobbyGameMode = GetLobbyGameMode(); // Assuming you have a method to obtain the reference to ALobbyGameMode
    if (LobbyGameMode)
    {
        LobbyGameMode->ToggleGameLogicActive(bActive);
    }
}

In ALobbyGameMode , the ToggleGameLogicActive function sets bGameLogicActive`accordingly.

void ALobbyGameMode::ToggleGameLogicActive(bool bActive)
{
    bGameLogicActive = bActive;
    GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Green, FString::Printf(TEXT("bGameLogicActive set to %s"), bActive ? TEXT("True") : TEXT("False")));
}

Question:

*What is the recommended and best practice for updating a flag in ALobbyGameMode from a widget, specifically when managing scenarios like manually creating a session in UGameMainMenu? My goal is to activate PostLogin based on the value of a flag.

Current Challenge:

  • When I manually create a session and attempt to set bGameLogicActive to true, it doesn’t seem to trigger the expected behavior in PostLogin.

I would greatly appreciate any insights, recommended practices, or examples that can help me efficiently handle this situation.

Thank you for your expertise!

Do you mean updating game mode options while you’re already running the game mode in the level you want, or before loading the level?

If before loading the new level / creating a new session, one thing you can do is use Option Strings and parse them to set values accordingly. Or pass the data around in something more persistent like in the game instance. Those are two things I have done.

As for the PostLogin thing you have not working, what’s going wrong? I assume you override PostLogin or use the Blueprints event and check whether bGameLogicActive is true or false?