Invoke a Pragma RPC #

In this section we’ll initialize the Pragma Party service and invoke an RPC to demonstrate how to use the SDK to utilize backend services and features.

Some Pragma services require calling an Initialize() method to prepare a service for use, for example to pre-populate caches. These service initialization methods should be invoked once after successfully logging into Pragma.

Initialize the Party Service #

Source\Unicorn\UnicornPlayerController.h

private:
    void InitializePartyService();

Call the party initialization helper upon login success.

Source\Unicorn\UnicornPlayerController.cpp

void AUnicornPlayerController::LogIn(const FString& Username)
{
    Player->LogIn(
        // ...
            if (Result.IsSuccessful())
            {
                // ...
                
                // initialize Party service after logging in
                InitializePartyService();
            }
        // ...
    );
}

Implement the party initialization helper

void AUnicornPlayerController::InitializePartyService()
{    
    Player->PartyApi().Initialize(
        UPragmaPartyApi::FOnCompleteDelegate::CreateWeakLambda(
        this, [](const TPragmaResult<>& PartyResult)
        {
            if (PartyResult.IsSuccessful())
            {
                UE_LOG(LogTemp, Display,
                    TEXT("Pragma -- Party service initialized successfully."));
            }
            else
            {
                UE_LOG(LogTemp, Error,
                    TEXT("Pragma -- Party service failed to initialize: %s"),
                    *PartyResult.GetErrorAsString());
            }
        })
    );
}

Create a Party #

Now that the Party service is ready, let’s add an exec function to create a Party.

Source\Unicorn\UnicornPlayerController.h

public:
	UFUNCTION(Exec)
	void CreateParty();

Source\Unicorn\UnicornPlayerController.cpp

void AUnicornPlayerController::CreateParty()
{
    Player->PartyApi().CreateParty({}, {}, UPragmaPartyApi::FOnCompleteDelegate::CreateWeakLambda(
        this, [](const TPragmaResult<>& Result)
        {
            if (Result.IsSuccessful())
            {
                UE_LOG(LogTemp, Display,
                    TEXT("Pragma -- Party create success!"));
            }
            else
            {
                UE_LOG(LogTemp, Error,
                    TEXT("Pragma -- Party create failed: %s"),
                    *Result.GetErrorAsString());
            }
        }));
}

Run the game #

  1. Ensure Pragma is running via ./pragma run or the Intellij run-pragma run configuration.
  2. Run the game
  3. Confirm the Party Service was initialized successfully.
    • Log: Pragma -- Party service initialized successfully.
  4. Run the exec function CreateParty
    • Open the console with backtick in the running game window and type CreateParty to call the exec function.
  5. Confirm your party was successfully created.
    • Log: Pragma -- Party create success!
  6. Success!

Recap #

You’ve successfully initialized the Pragma Party service and called an RPC! This demonstrates the core integration pattern for calling backend services with Pragma.

From here check out the provided how-to guides for examples on how to use various Pragma services. Good luck and have fun!