Skip to main content

Player Sign-in

Nothing replicates until a player is signed in. Once sign-in succeeds the SDK opens the realtime connection itself, so this is the one step every page in this section assumes has already happened. This page shows the most basic way to do it and nothing more.

When you touch this​

Once per project, at startup, before any entity, event, or property.

Sign in with a password​

The Game Instance signs in from Init: bind On Login and On UDP Connection Success on the Crowdy SDK Subsystem, then call Login with an email and password read from Config/DefaultGame.ini. The first handler reports the sign-in; the second fires when the connection is up.

// LanternGameInstance.h
#include "Subsystem/CrowdySDKSubsystem.h"
#include "LanternGameInstance.generated.h"

UCLASS(Config = Game)
class ULanternGameInstance : public UGameInstance
{
GENERATED_BODY()

public:
virtual void Init() override;

// A development account read from Config/DefaultGame.ini. Never ship credentials in a game.
UPROPERTY(Config)
FString Email;

UPROPERTY(Config)
FString Password;

private:
UFUNCTION()
void HandleLogin(bool bSuccess, FString Message);

UFUNCTION()
void HandleConnected();
};

// LanternGameInstance.cpp
#include "LanternGameInstance.h"

void ULanternGameInstance::Init()
{
Super::Init();
UCrowdySDKSubsystem* Sdk = GetSubsystem<UCrowdySDKSubsystem>();
Sdk->OnLogin.AddDynamic(this, &ULanternGameInstance::HandleLogin);
Sdk->OnUDPConnectionSuccess.AddDynamic(this, &ULanternGameInstance::HandleConnected);
Sdk->Login(Email, Password);
}

void ULanternGameInstance::HandleLogin(bool bSuccess, FString Message)
{
UE_LOG(LogTemp, Log, TEXT("Login %s %s"), bSuccess ? TEXT("ok") : TEXT("failed:"), *Message);
}

void ULanternGameInstance::HandleConnected()
{
// From here on entities register on the wire and a host is elected.
UE_LOG(LogTemp, Log, TEXT("Connected to the app"));
}

Make it the project's Game Instance under Project Settings, Maps & Modes, Game Instance Class, and give it a test account in Config/DefaultGame.ini (YourModule is your game module's name):

[/Script/YourModule.LanternGameInstance]
Email=you@example.com
Password=your-test-password
A test account belongs in a config file or a pin default, never in shipped code.
Never print, log, or store the token in the result.

The Result a success carries holds the player's UserID and a token the SDK already keeps for you. The SDK's own On Login event on the Crowdy SDK Subsystem carries a message and no credential, on purpose; keep anything you put on screen the same way.

If this machine signed in before, restore instead of asking: call RestoreSession first and show the widget only on its error path, as Authentication shows; the connection then comes up exactly as after a Login.

Success signal. The log reads Login ok, then Connected to the app. From then on Get UDP Connection State on the subsystem reads connected, and the rest of the Runtime section applies. Start replicating your pawn only from that moment: On UDP Connection Success fires once the server has assigned this client and its readiness wait has elapsed, an update sent earlier is not held for it, and the Quickstart spawns the pawn from the connected handler for that reason.

  • Authentication: register, magic link, social sign-in, restoring a saved session, sign-out, and the events.
  • Quickstart: this step in the context of one complete lantern, and the pawn that makes the signed-in player present.
  • Connection and reconnect: what the SDK does once the sign-in succeeds.