By using AWS re:Post, you agree to the AWS re:Post Terms of Use

How to get all active GameLift game sessions on a Fleet with UnrealEngine SDK/C++ ?

0

Hey there, I am looking to find all game sessions on a fleet/server using C++ with Unreal Engine and would like some direction on where to begin code-wise.

Checking the GameLiftSDK module from the plugin in UE, there is no built in implementation for this form of request. It does exist in the API reference as 'DescribeGameSessions', so my question is:** how can I leverage the API reference in unreal engine c++ and get that list of game sessions and their data**?

API Link: https://docs.aws.amazon.com/gamelift/latest/apireference/API_DescribeGameSessions.html

Any help would be greatly appreciated.

1 Answer
0

To retrieve all active game sessions on a GameLift fleet using the Unreal Engine SDK and C++, you'll need to use the DescribeGameSessions operation. Since this operation is not directly implemented in the GameLiftSDK module of the Unreal Engine plugin, you'll need to make a custom implementation using the AWS SDK for C++.

Here's a general approach to accomplish this:

  1. First, ensure you have the AWS SDK for C++ integrated into your Unreal Engine project.

  2. Include the necessary AWS GameLift headers in your C++ file.

  3. Create an AWS GameLift client.

  4. Construct a DescribeGameSessionsRequest object, setting the FleetId parameter to your target fleet's ID.

  5. Call the DescribeGameSessions method on the GameLift client, passing in your request object.

  6. Process the response, which will contain a collection of GameSession objects representing the active game sessions.

Here's a basic code structure to get you started:

#include <aws/gamelift/GameLiftClient.h>
#include <aws/gamelift/model/DescribeGameSessionsRequest.h>

void GetActiveGameSessions(const FString& FleetId)
{
    Aws::GameLift::GameLiftClient gameLiftClient;
    
    Aws::GameLift::Model::DescribeGameSessionsRequest request;
    request.SetFleetId(TCHAR_TO_UTF8(*FleetId));
    
    auto outcome = gameLiftClient.DescribeGameSessions(request);
    
    if (outcome.IsSuccess())
    {
        const auto& gameSessions = outcome.GetResult().GetGameSessions();
        for (const auto& session : gameSessions)
        {
            // Process each game session
            FString sessionId = UTF8_TO_TCHAR(session.GetGameSessionId().c_str());
            // ... handle other session properties
        }
    }
    else
    {
        // Handle error
        UE_LOG(LogTemp, Error, TEXT("Failed to describe game sessions: %s"), 
               UTF8_TO_TCHAR(outcome.GetError().GetMessage().c_str()));
    }
}

Remember to handle pagination if you have a large number of game sessions, as the API might not return all results in a single call. You can use the NextToken in the response to make subsequent requests and retrieve all game sessions.

Also, note that this operation retrieves game sessions in ACTIVE status. If you need to retrieve game sessions in other statuses, you might need to adjust your approach or use alternative methods.

Lastly, ensure you have the necessary permissions set up in your AWS account to make these API calls from your game client or server.
Sources
DescribeGameSessions - Amazon GameLift
DescribeGameSessionDetails - Amazon GameLift

profile picture
answered 23 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions