プレイヤープリセットに UGC を使用する
Overview
User Generated Content (UGC) is a service that manages in-game content that has been created by your players. UGC can be a powerful way to increase engagement, retention, and loyalty among your customers, as well as to attract new ones. There are different forms of UGC, depending on the game. The opportunities are endless, but some of these items include: customizing the game character, customizing the color of a vehicle, new aspects of a weapon, creating custom maps, and so much more.
There are a lot of games that implement deep customization to their player content. With a content customization, It can increase the player's immersion and engagement with the game world, as they can create content that reflects their personality, preferences, and style. Also, it can encourage social interaction and community building among players, especially if they can make a preset out of their content and share it with others. By allowing players to showcase their creativity and identity through their content, developers can create a loyal fan base and generate positive word-of-mouth for their game.
This article walks you through how to use the UGC service to store player-generated content, display them within the game client, and use them according to your game use case.
Prerequisites
You will need access to:
- The AccelByte Gaming Services (AGS) Admin Portal
- The AGS Unreal or Unity SDK
- The AGS UGC API documentation for reference.
Create channel to store player content
UGC service manages player content based on channels. A channel is a generic entity that is used to categorize players' content. You can use channels to group contents by region, language, build version, patch, content category, or any other cases that are needed for the game scenario. It can be hardcoded or the game could let the player manage their own channel.
Create a channel using the Client SDK
You can use this function to create a channel.
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString ChannelName = "YourChannelName";
ApiClient->UGC.CreateChannel(ChannelName, THandler<FAccelByteModelsUGCChannelResponse>::CreateLambda([](const FAccelByteModelsUGCChannelResponse& Result)
{
// Do something if CreateV2Channel succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if CreateV2Channel fails
}));
string channelName = "YourChannelName";
UGC ugc = AccelByteSDK.GetClientRegistry().GetApi().GetUgc();
ugc.CreateChannel(channelName, result =>
{
if (result.IsError)
{
// Do something if CreateChannel fails
Debug.Log($"Error CreateChannel, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Get channel id
string channelId = result.Value.id;
// Do something if CreateChannel succeeds
});
Get the list of the player channel using the Client SDK
You can use this function to list of the player channel.
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString UserId = "YourUserId";
int32 Limit = 1000;
int32 Offset = 0;
FString ChannelName = "YourChannelName";
ApiClient->UGC.GetChannels(UserId, THandler<FAccelByteModelsUGCChannelsPagingResponse>::CreateLambda([](const FAccelByteModelsUGCChannelsPagingResponse& Result)
{
// Do something if GetChannels succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetChannels fails
}), Limit, Offset, ChannelName);
string userId = "YourUserId";
string channelName = "YourChannelName";
int limit = 1000;
int offset = 0;
UGC ugc = AccelByteSDK.GetClientRegistry().GetApi().GetUgc();
ugc.GetChannels(userId, result =>
{
if (result.IsError)
{
// Do something if GetChannels fails
Debug.Log($"Error GetChannels, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if GetChannels succeeds
}, offset, limit, channelName);
Store player content in UGC
If you want to save your player content in UGC service as preset, you need to create a file that contains all the customization options you have applied to your player content. This file will store the information about your player content.
To create player content in UGC service, you need to complete two steps. First, you need to request a pre-signed URL from the service that will allow you to upload your file. In this step, you can also specify the basic metadata for the player content, such as name, tags, type, and subtype. Second, you need to use the pre-signed URL to upload your file to the service.
Get a pre-signed URL using the Client SDK
You can use this function to set the player content metadata and get a pre-signed URL that you can use to upload your player content to cloud storage.
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString ChannelId = "YourChannelId";
FAccelByteModelsCreateUGCRequestV2 UGCRequest = {};
UGCRequest.ContentType = "PNG";
UGCRequest.FileExtension = "PNG";
UGCRequest.Name = "UGC Integration UE4";
UGCRequest.Type = "UGC Type";
UGCRequest.SubType = "UGC SubType";
UGCRequest.Tags = { "UGC Tag1", "UGC Tag2"};
ApiClient->UGC.CreateV2Content(ChannelId, UGCRequest, THandler<FAccelByteModelsUGCCreateUGCResponseV2>::CreateLambda([](const FAccelByteModelsUGCCreateUGCResponseV2& Result)
{
// Do something if CreateV2Content succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if CreateV2Content fails
}));
string channelId = "YourChannelId";
CreateUGCRequestV2 createRequest = new CreateUGCRequestV2
{
ContentType = "PNG",
FileExtension = "PNG",
Name = "UGC Integration Unity",
Type = "UGC Type",
Tags = new[] { "UGC Tag1", "UGC Tag2" },
CustomAttributes = new Dictionary<string, object>()
};
UGC ugc = AccelByteSDK.GetClientRegistry().GetApi().GetUgc();
ugc.CreateContentV2(channelId, createRequest, result =>
{
if (result.IsError)
{
// Do something if CreateContentV2 fails
Debug.Log($"Error CreateContentV2, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
string presignedUrl = result.Value.PayloadUrl[0].url; // you can get presigned url from the result
// Do something if CreateContentV2 succeeds
});
Upload player content file using the Client SDK
To upload player content to cloud storage, use the following function:
You'll need a pre-signed URL for this function. See Get a pre-signed URL using the Client SDK.
- Unreal Engine
- Unity
FString Url = "PayloadUGCUrlToUpload";
TArray<uint8> DataUpload = { 106, 35, 171, 106, 138, 197, 77, 94, 182, 18, 99, 9, 245, 110, 45, 197, 22, 35};
FAccelByteNetUtilities::UploadTo(Url, DataUpload, FHttpRequestProgressDelegate::CreateLambda([](const FHttpRequestPtr& Request, int32 BytesSent, int32 BytesReceived)
{
// Do something if UploadTo still in progress successful
}),FVoidHandler::CreateLambda([]()
{
// Do something if UploadTo succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if UploadTo fails
}));
string url = "YourPresignedUrl";
byte[] yourDataToUpload;
AccelByteNetUtilities.UploadTo(url, yourDataToUpload, result =>
{
if (result.IsError)
{
// Do something if UploadTo fails
Debug.Log($"Error UploadTo, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if UploadTo succeeds
});
Add screenshots to player content
One way to make your player content file more attractive and informative is to add a screenshot that shows how it looks in the game. A screenshot can capture the visual effects and details that you have created with your preset file.
Get a pre-signed URL for uploading the screenshot using the Client SDK
You can use this function to get a pre-signed URL that you can use to upload your screenshot for a specific player content.
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString ContentId = "YourContentId";
FString UserId = "UserId";
FAccelByteModelsUGCUploadScreenshotV2 Screenshot;
Screenshot.Description = "Screenshot Test Description";
Screenshot.ContentType = "png";
Screenshot.FileExtension = "png";
FAccelByteModelsUGCUploadScreenshotsRequestV2 ScreenshotsRequest = {};
ScreenshotsRequest.Screenshots = { Screenshot };
ApiClient->UGC.UploadV2ScreenshotContent(ContentId, ScreenshotsRequest, THandler<FAccelByteModelsUGCUpdateContentScreenshotResponse>::CreateLambda([](const FAccelByteModelsUGCUpdateContentScreenshotResponse& Result)
{
// Do something if UploadV2ScreenshotContent succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if UploadV2ScreenshotContent fails
}));
string contentId = "YourContentId";
ScreenshotRequest screenshotRequest = new ScreenshotRequest()
{
description = "UGC Screenshot Description",
fileExtension = UGCFileExtension.PNG
};
ScreenshotsRequest screenshotsRequest = new ScreenshotsRequest()
{
screenshots = new[] { screenshotRequest }
};
UGC ugc = AccelByteSDK.GetClientRegistry().GetApi().GetUgc();
ugc.UploadContentScreenshotV2(contentId, screenshotsRequest, result =>
{
if (result.IsError)
{
// Do something if UploadContentScreenshotV2 fails
Debug.Log($"Error UploadContentScreenshotV2, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if UploadContentScreenshotV2 succeeds
});
Upload the screenshot using the Client SDK
To upload screenshot for a specific player content to cloud storage, use this function:
You'll need a pre-signed URL for this function. See Get a pre-signed URL using the Client SDK.
- Unreal Engine
- Unity
FString Url = "PayloadScreenshotUrlToUpload";
TArray<uint8> DataUpload = { 35, 171, 106, 138, 197, 77, 94, 182, 18, 99, 9, 245, 110, 45, 197, 35};
FAccelByteNetUtilities::UploadTo(Url, DataUpload, FHttpRequestProgressDelegate::CreateLambda([](const FHttpRequestPtr& Request, int32 BytesSent, int32 BytesReceived)
{
// Do something if UploadTo still in progress successful
}),FVoidHandler::CreateLambda([]()
{
// Do something if UploadTo succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if UploadTo fails
}));
string url = "YourPresignedUrl";
byte[] yourDataToUpload;
AccelByteNetUtilities.UploadTo(url, yourDataToUpload, result =>
{
if (result.IsError)
{
// Do something if UploadTo fails
Debug.Log($"Error UploadTo, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if UploadTo succeeds
});
Display player content by share code
When a player creates a player content, UGC service will generate a unique share code for it. The player can share the share code with other players to show off their creation or invite them to try it out. Other players can use the share code to access the details of the preset. They can also apply the preset to their own game or modify it as they wish.
Display player content by share code using Client SDK
This example below shows you how to retrieve the player content using the sharecode.
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString ShareCode = "YourUGCShareCode";
ApiClient->UGC.GetV2ContentByShareCode(ShareCode, THandler<FAccelByteModelsUGCContentResponseV2>::CreateLambda([](const FAccelByteModelsUGCContentResponseV2& Result)
{
// Do something if GetV2ContentByShareCode succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetV2ContentByShareCode fails
}));
string shareCode = "YourUGCShareCode";
UGC ugc = AccelByteSDK.GetClientRegistry().GetApi().GetUgc();
ugc.GetContentByShareCodeV2(shareCode, result =>
{
if (result.IsError)
{
// Do something if GetContentByShareCodeV2 fails
Debug.Log($"Error GetContentByShareCodeV2, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if GetContentByShareCodeV2 succeeds
});
Modify player content
When modifying player content, you can only update the player content metadata or the preset file.
To modify the preset file in UGC service, you need to do the following:
- Request a pre-signed URL from the service that will allow you to upload your new file.
- Use the pre-signed URL to upload your file to the service.
- Commit the changes by updating the new file location.
Update player content metadata using the Client SDK
To update the player content metadata, use this function:
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString ChannelId = "YourChannelId";
FString ContentId = "YourContentId";
FAccelByteModelsModifyUGCRequestV2 ModifyRequest = {};
ModifyRequest.Name = "Updated UGC Integration UE4";
ModifyRequest.Type = "Updated UGC Type";
ModifyRequest.SubType = "Updated UGC SubType";
ModifyRequest.Tags = { "Updated UGC Tag1", "Updated UGC Tag2"};
ApiClient->UGC.ModifyV2Content(ChannelId, ContentId, ModifyRequest, THandler<FAccelByteModelsUGCModifyUGCResponseV2>::CreateLambda([](const FAccelByteModelsUGCModifyUGCResponseV2& Result)
{
// Do something if ModifyV2Content succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if ModifyV2Content fails
}));
string channelId = "YourChannelId";
string contentId = "YourContentId";
ModifyUGCRequestV2 ModifyRequest = new ModifyUGCRequestV2
{
Name = "Updated UGC Integration Unity",
Type = "Updated UGC Type",
Tags = new[] { "Updated UGC Tag1", "Updated UGC Tag2" },
CustomAttributes = new Dictionary<string, object>()
};
UGC ugc = AccelByteSDK.GetClientRegistry().GetApi().GetUgc();
ugc.ModifyContentV2(channelId, contentId, ModifyRequest, result =>
{
if (result.IsError)
{
// Do something if ModifyContentV2 fails
Debug.Log($"Error ModifyContentV2, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if ModifyContentV2 succeeds
});
Request a pre-signed URL using the Client SDK
To get a pre-signed URL that you can use to upload your updated player content to cloud storage, use this function:
- Unreal Engine
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString ChannelId = "YourChannelId";
FString ContentId = "YourContentId";
FAccelByteModelsUploadContentURLRequestV2 UploadRequest = {};
UploadRequest.ContentType = "PNG";
UploadRequest.FileExtension = "PNG";
ApiClient->UGC.GenerateUploadContentURLV2(ChannelId, ContentId, UploadRequest, THandler<FAccelByteModelsUGCUploadContentURLResponseV2>::CreateLambda([](const FAccelByteModelsUGCUploadContentURLResponseV2& Result)
{
// Do something if GenerateUploadContentURLV2 succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GenerateUploadContentURLV2 fails
}));
Upload updated player content file using the Client SDK
To upload the updated player content file to cloud storage, use this function:
You'll need a pre-signed URL for this function. See Get a pre-signed URL using the Client SDK.
- Unreal Engine
- Unity
FString Url = "PayloadUpdatedUGCUrlToUpload";
TArray<uint8> DataUpload = { 106, 35, 171, 106, 138, 197, 94, 182, 18, 99, 9, 245, 110, 45, 197, 35};
FAccelByteNetUtilities::UploadTo(Url, DataUpload, FHttpRequestProgressDelegate::CreateLambda([](const FHttpRequestPtr& Request, int32 BytesSent, int32 BytesReceived)
{
// Do something if UploadTo still in progress successful
}),FVoidHandler::CreateLambda([]()
{
// Do something if UploadTo succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if UploadTo fails
}));
string url = "YourPresignedUrl";
byte[] yourDataToUpload;
AccelByteNetUtilities.UploadTo(url, yourDataToUpload, result =>
{
if (result.IsError)
{
// Do something if UploadTo fails
Debug.Log($"Error UploadTo, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if UploadTo succeeds
});
Update player content file location using the Client SDK
Once the player content file is uploaded, commit the changes to make sure the new file location is updated by using the following function:
- Unreal Engine
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString ChannelId = "YourChannelId";
FString ContentId = "YourContentId";
FString FileExtension = "PNG";
FString S3Key = "YourContentS3Key";
ApiClient->UGC.UpdateContentFileLocationV2(ChannelId, ContentId, FileExtension, S3Key, THandler<FAccelByteModelsUGCUpdateContentFileLocationResponseV2>::CreateLambda([](const FAccelByteModelsUGCUpdateContentFileLocationResponseV2& Response)
{
// Do something if UpdateContentFileLocationV2 succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if UpdateContentFileLocationV2 fails
}));
Delete player content
Delete player content using the Client SDK
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
FString ChannelId = "YourChannelId";
FString ContentId = "YourContentId";
ApiClient->UGC.DeleteV2Content(ChannelId, ContentId, FVoidHandler::CreateLambda([]()
{
// Do something if DeleteV2Content succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if DeleteV2Content fails
}));
string channelId = "YourChannelId";
string contentId = "YourContentId";
UGC ugc = AccelByteSDK.GetClientRegistry().GetApi().GetUgc();
ugc.DeleteContentV2(channelId, contentId, result =>
{
if (result.IsError)
{
// Do something if DeleteContentV2 fails
Debug.Log($"Error DeleteContentV2, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
return;
}
// Do something if DeleteContentV2 succeeds
});