メインコンテンツまでスキップ

パーティをゲームに統合する

Last updated on July 14, 2026

注釈:本資料はAI技術を用いて翻訳されています。

Overview

AccelByte Gaming Services (AGS) Session には、マルチプレイヤープレイのパーティを処理するサービスである AGS Party が含まれています。プレイヤーは以下のような複数の方法でパーティを操作できます。

  • User Party Info: パーティ ID、リーダー ID、パーティメンバーのリストなど、自分のパーティに関する情報をプレイヤーに表示します。
  • Create Party: プレイヤーが他のプレイヤーが参加できる新しいパーティを作成できるようにします。
  • Invite to Party: プレイヤーが自分のパーティに友達を招待できるようにします。招待が送信されると、招待者と被招待者の両方に通知が届きます。
  • Join Party: プレイヤーが招待されたパーティに参加できるようにします。プレイヤーがパーティに参加すると、招待者と他のパーティメンバーに通知が届きます。
  • Cancel Party Invitation: プレイヤーがパーティへの招待を取り消せるようにします。被招待者と招待者の両方に、招待が取り消されたことを通知します。被招待者は取り消し後、以前の招待に参加することはできません。
  • Reject Party Invitation: プレイヤーがパーティへの招待を拒否できるようにします。招待者には、招待が拒否されたことが通知されます。
  • Promote a Member as a Party Leader: プレイヤーが他のプレイヤーをパーティリーダーに設定できるようにします。
  • Kick from Party: パーティリーダーがパーティから他のプレイヤーを削除(キック)できるようにします。
  • Leave Party: プレイヤーが既に参加しているパーティから離脱できるようにします。プレイヤーがパーティから離脱すると、他のパーティメンバーに通知が届きます。

この記事では、AGS Party を使用したプレイヤーパーティの統合について説明します。

Permissions

権限は、AGS 内の特定のリソースへのアクセスを許可するために使用されます。Party Session V2 を管理する前に、アカウントに以下の権限があることを確認してください。

用途権限アクション
セッションテンプレートを追加、編集、削除するADMIN:NAMESPACE:*:SESSION:CONFIGURATIONCREATE, READ, UPDATE, DELETE
Session and Parties でセッションを表示するNAMESPACE:*:SESSION:GAMECREATE, READ, UPDATE, DELETE

Prerequisites

Session Interface V2 を使用するには、以下のファイルをインクルードします。

#include "OnlineSubsystem.h"
#include "OnlineSubsystemUtils.h"
#include "Interfaces/OnlineSessionInterface.h"
#include "Engine/World.h"
#include "Engine/GameEngine.h"

#include "OnlineSessionInterfaceV2AccelByte.h"
#include "OnlineSubsystemAccelByteSessionSettings.h"
#include "OnlineSubsystemSessionSettings.h"

以下の関数を使用して、ゲームから FOnlineSessionV2AccelByteLocalPlayerId を取得します。

注記

このチュートリアルの以降の部分では、インターフェースの各機能に焦点を当てるため、このコードスニペットは省略します。

// Get FOnlineSessionV2AccelByte from the game
const UWorld* World = GEngine->GetCurrentPlayWorld();
const IOnlineSubsystem* Subsystem = Online::GetSubsystem(World, ACCELBYTE_SUBSYSTEM);
const auto SessionInterface = StaticCastSharedPtr<FOnlineSessionV2AccelByte>(Subsystem->GetSessionInterface());

// Get LocalPlayerId from the game
const int PlayerIndex = 0;
const ULocalPlayer* LocalPlayer = GEngine->GetLocalPlayerFromControllerId(GEngine->GetCurrentPlayWorld(), PlayerIndex );
const FUniqueNetIdPtr LocalPlayerId = LocalPlayer->GetPreferredUniqueNetId().GetUniqueNetId();

Create a party

プレイヤーは、マッチメイキングに使用できるパーティを作成できます。プレイヤーは同時に1つのパーティしか作成できず、作成したパーティのリーダーになります。

SessionInterface->AddOnCreateSessionCompleteDelegate_Handle(
FOnCreateSessionCompleteDelegate::CreateLambda([](const FName SessionName, const bool bWasSuccessful)
{
if (SessionName == NAME_PartySession)
{
if(!bWasSuccessful)
{
// Create party error handling
}
// Party created handling
}
}));

FOnlineSessionSettings NewSessionSettings;
NewSessionSettings.NumPrivateConnections = 4;

NewSessionSettings.Set(SETTING_SESSION_JOIN_TYPE, TEXT("INVITE_ONLY"));
NewSessionSettings.Set(SETTING_SESSION_TYPE, SETTING_SESSION_TYPE_PARTY_SESSION);
NewSessionSettings.Set(SETTING_SESSION_TEMPLATE_NAME, TEXT("TemplateNameFromAP"));

SessionInterface->CreateSession(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, NewSessionSettings);

Invite to party

プレイヤーは他のプレイヤーを自分のパーティに招待できます。被招待者にはパーティへの招待を受け取ったことが通知され、現在のパーティメンバーにも誰かがパーティに招待されたことが通知されます。

// Listen for party invitations
SessionInterface->AddOnV2SessionInviteReceivedDelegate_Handle(FOnV2SessionInviteReceivedDelegate::CreateLambda(
[](const FUniqueNetId& UserId, const FUniqueNetId&, const FOnlineSessionInviteAccelByte& InviteResult)
{
if (InviteResult.SessionType == EAccelByteV2SessionType::PartySession)
{
// Handle party session invite notifications
// InviteResult contains the party details
}
}));

// Send invitation to other user
SessionInterface->SendSessionInviteToFriend(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, OtherUserPlayerId.ToSharedRef().Get());

Cancel outgoing party invitation

プレイヤーは送信済みの招待を取り消すことができます。被招待者と招待者には、招待が取り消されたことが通知されます。被招待者は取り消し後、以前の招待を受け入れることはできません。

// Invitee and inviter listen for session invite canceled notification.
auto OnSessionInviteCanceledDelegate = SessionInterface->AddOnSessionInviteCanceledDelegate_Handle(
FOnSessionInviteCanceledDelegate::CreateLambda([](const FString& SessionID) // ID of canceled party.
{
// Received invitation canceled.
}));

// Party leader (inviter) cancel invitation.
FName PartyName = NAME_PartySession;
auto OnCancelSessionInviteCompleteDelegate = SessionInterface->AddOnCancelSessionInviteCompleteDelegate_Handle(FOnCancelSessionInviteCompleteDelegate::CreateLambda(
[&](const FUniqueNetId& LocalUserId, FName SessionName, const FUniqueNetId& Invitee, const FOnlineError& ErrorInfo)
{
bool bInvitationCanceled = ErrorInfo.bSucceeded;
// Cancel session invitation complete.
}));

SessionInterface->CancelSessionInvite(PlayerIndex, PartyName, *InviteeUniqueNetId);

Join a party

パーティに招待されたプレイヤーは、招待を受け入れてパーティに参加できます。パーティの被招待者にはパーティに参加したことが通知され、現在のパーティメンバーにも誰かがパーティに参加していることが通知されます。

// Listen for party invitations
SessionInterface->AddOnV2SessionInviteReceivedDelegate_Handle(FOnV2SessionInviteReceivedDelegate::CreateLambda(
[](const FUniqueNetId& UserId, const FUniqueNetId&, const FOnlineSessionInviteAccelByte& InviteResult)
{
if (InviteResult.SessionType == EAccelByteV2SessionType::PartySession)
{
// Handle party session invite notifications
// InviteResult contains the party details
}
}));

// Add delegate for joining a party session completing
SessionInterface->AddOnJoinSessionCompleteDelegate_Handle(
FOnJoinSessionCompleteDelegate::CreateLambda([](FName SessionName, EOnJoinSessionCompleteResult::Type Result){
if (SessionName == NAME_PartySession)
{
// Join party session completed, check the result
}
}));

// Join the party session
FOnlineSessionInviteAccelByte Invitation; // The invitation from the notification
SessionInterface->JoinSession(*LocalPlayerId.Get(), NAME_PartySession, Invitation.Session);

Reject a party invitation

プレイヤーがパーティに招待されると、その招待を拒否することを選択できます。パーティの被招待者と現在のパーティメンバーには、招待が拒否されたことが通知されます。

FOnRejectSessionInviteComplete OnRejectSessionInviteComplete = FOnRejectSessionInviteComplete::CreateLambda([](const bool bWasSuccessful)
{
if (bWasSuccessful)
{
// Successfully rejected party invitation
}
});

// Join the party session
FOnlineSessionInviteAccelByte Invitation; // The invitation from the notification
SessionInterface->RejectInvite(LocalPlayerId.ToSharedRef().Get(), Invitation, OnRejectSessionInviteComplete);

Promote a member to party leader

パーティリーダーは、他のパーティメンバーを新しいパーティリーダーに昇格させることができます。新しいパーティリーダーは、すべてのパーティメンバーに通知されます。昇格させる新しいパーティリーダーは、パーティメンバーの特定のユーザー ID によって指定します。

// Listen for party session updates
SessionInterface->AddOnSessionUpdateReceivedDelegate_Handle(FOnSessionUpdateReceivedDelegate::CreateLambda([SessionInterface](FName SessionName)
{
if (SessionName == NAME_PartySession)
{
// There is an update notification for the party
auto LatestPartySession = SessionInterface->GetNamedSession(NAME_PartySession);
}
}));

// Promote another party member to party leader
FOnPromotePartySessionLeaderComplete OnPromotePartySessionLeaderComplete =
FOnPromotePartySessionLeaderComplete::CreateLambda([](const FUniqueNetId& PromotedUserId, const FOnlineError& Result)
{
if (Result.bSucceeded)
{
// Successfully promoted new party leader
}
});

SessionInterface->PromotePartySessionLeader(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, OtherUserPlayerId.ToSharedRef().Get(), OnPromotePartySessionLeaderComplete);

Kick a player from a party

パーティリーダーは、パーティメンバーをパーティから削除(キック)する権限を持っています。キックされたパーティメンバーには、パーティからキックされたことが通知され、現在のパーティメンバーにも誰かがパーティからキックされたことが通知されます。

// Listen for notifications for kicking players from a party session
SessionInterface->AddOnKickedFromSessionDelegate_Handle(FOnKickedFromSessionDelegate::CreateLambda([](FName SessionName)
{
if (SessionName == NAME_PartySession)
{
// Player kicked from party
}
}));

// Kick player from party session
FOnKickPlayerComplete OnKickPlayerComplete =
FOnKickPlayerComplete::CreateLambda([](const bool bWasSuccessful, const FUniqueNetId& KickedPlayerId)
{
if (bWasSuccessful)
{
// Player successfully kicked from the party
}
});

SessionInterface->KickPlayer(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, PlayerIdToKick.ToSharedRef().Get());

Leave a party

パーティメンバーは、自分のパーティから離脱することを選択できます。パーティリーダーがパーティを離脱すると、パーティのリーダーシップは自動的に他のパーティメンバーに引き継がれます。パーティを離脱したパーティメンバーには、パーティを離脱したことが通知され、現在のパーティメンバーにも誰かがパーティを離脱していることが通知されます。

// Listen for party session update
SessionInterface->AddOnSessionUpdateReceivedDelegate_Handle(FOnSessionUpdateReceivedDelegate::CreateLambda([SessionInterface](FName SessionName)
{
if (SessionName == NAME_PartySession)
{
// There is an update notification for party
auto LatestPartySession = SessionInterface->GetNamedSession(NAME_PartySession);
}
}));

// Leave a party
PartySession = SessionInterface->GetNamedSession(NAME_PartySession);
auto PartySessionInfo = StaticCastSharedPtr<FOnlineSessionInfoAccelByteV2>(PartySession->SessionInfo);
FString PartyId = PartySessionInfo->GetBackendSessionDataAsPartySession()->ID;

FOnLeaveSessionComplete OnLeavePartyComplete =
FOnLeaveSessionComplete::CreateLambda([](const bool bWasSuccessful, FString SessionId)
{
if (bWasSuccessful)
{
// Successfully left a party
}
});
SessionInterface->LeaveSession(LocalPlayerId.ToSharedRef().Get(), EAccelByteV2SessionType::PartySession, PartyId, OnLeavePartyComplete);

Party codes

パーティリーダーは、プレイヤーが自分のパーティに参加できるようにパーティコードを送信できます。パーティコードを更新または取り消せるのはパーティリーダーのみです。

Get a party code

コードが生成されると、パーティリーダーはそのコードを取得して他のプレイヤーに共有できます。この関数は、パーティリーダーがパーティコードを取得できるようにします。

FString Code;
auto PartySession = SessionInterface->GetNamedSession(NAME_PartySession);
auto PartySessionInfo = StaticCastSharedPtr<FOnlineSessionInfoAccelByteV2>(PartySession->SessionInfo);
FString PartyCode = PartySessionInfo->GetBackendSessionDataAsPartySession()->Code;

PartySession->SessionSettings.Get(SETTING_PARTYSESSION_CODE, PartyCode);

Generate or refresh a party code

パーティコードを生成または更新するには、以下の関数を使用します。

const FOnGenerateNewPartyCodeComplete OnGenerateNewPartyCodeCompleteDelegate =
FOnGenerateNewPartyCodeComplete::CreateLambda([](const bool bWasSuccessful, FString NewPartyCode)
{
if (bWasSuccessful)
{
// successfully generate new party code
}
});

Revoke a party code

パーティリーダーは、パーティコードを取り消すことができます。パーティコードが取り消されると、プレイヤーはそれを使用してパーティに参加できなくなります。この関数は、パーティリーダーがパーティコードを取り消せるようにします。

const FOnRevokePartyCodeComplete OnRevokePartyCodeComplete =
FOnRevokePartyCodeComplete::CreateLambda([](const bool bWasSuccessful)
{
if (bWasSuccessful)
{
// Successfully revoked party code
}
});

SessionInterface->RevokePartyCode(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, OnRevokePartyCodeComplete);

Join a party with a party code

パーティコードを送られたプレイヤーは、それを使用してパーティに参加できます。この関数は、プレイヤーがパーティコードを使用してパーティに参加できるようにします。

// Add delegate for the completion of joining a party session
SessionInterface->AddOnJoinSessionCompleteDelegate_Handle(
FOnJoinSessionCompleteDelegate::CreateLambda([](FName SessionName, EOnJoinSessionCompleteResult::Type Result){
if (SessionName == NAME_PartySession)
{
// Join party session completed, check the result
}
}));

// Party code from party leader
FString PartyCode = TEXT("PARTY_CODE");
SessionInterface->JoinSession(LocalPlayerId.ToSharedRef().Get(), NAME_PartySession, PartyCode);

Refresh party session

ゲームセッションは、Refresh Session メソッドを使用してバックエンドと同期するように更新できます。指定する SessionName パラメータは NAME_PartySession に対応させることができます。

SessionInterface->RefreshSession(SessionName, FOnRefreshSessionComplete::CreateLambda([]()
{
// On refresh session complete
}));

Refresh active sessions

問題を防止し、バックエンドとの適切な同期を確保するために、以下の関数を使用して、クライアント側にローカルにキャッシュされているすべてのアクティブなセッションを更新します。

SessionInterface->RefreshActiveSessions(FOnRefreshActiveSessionsComplete::CreateLambda(
[&](bool bWasSuccessful)
{
// On refresh active sessions complete
}));