Create UGC In-Game

In this How-to, we’ll go through the process of creating a UGC asset candidate, adding some information to it and promoting it to a UGC asset that can be viewed by all players in your game.

Prerequisites

Create an asset candidate

The first thing a user needs to do is to create an asset candidate, which is the “working state” of UGC in LootLocker.

// Name is required when creating an asset candidate
string name = "New Asset Candidate";

// The below additional variables are optional
Dictionary<string, string> kv_storage = new Dictionary<string, string>();
kv_storage.Add("key", "value"); // Optional
Dictionary<string, string> filters = new Dictionary<string, string>();
filters.Add("key", "value"); // Optional
Dictionary<string, string> data_entities = new Dictionary<string, string>();
filters.Add("data", "name"); // Optional
int context_id = -1; // Optional

string asset_candidate_id = "";
LootLockerSDKManager.CreatingAnAssetCandidate(name, kv_storage, filters, data_entities, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully created asset candidate with ID: " + response.asset_candidate_id);
        // Save the asset_candidate_id for future requests
        asset_candidate_id = response.asset_candidate_id;
    }
    else
    {
        Debug.Log("Error asset candidate");
    }
});

We need the asset_instance_id for future requests, wait for the request to be done and save the asset_candidate_id before calling the next request.

Working with the asset candidate

After the asset candidate has been created you have several ways of modifying it:

Delete the asset candidate

int assetCandidateID = 13;
LootLockerSDKManager.DeletingAnAssetCandidate(assetCandidateID, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully deleted asset candidate");
    }
    else
    {
        Debug.Log("Error deleting asset canddidate");
    }
});

Add files to the asset candidate

int assetCandidateID = 12;
string filePath = "Assets/Resources/300.jpg";
string fileName = "300.jpg";
LootLocker.LootLockerEnums.FilePurpose fileType = LootLocker.LootLockerEnums.FilePurpose.primary_thumbnail;
LootLockerSDKManager.AddingFilesToAssetCandidates(assetCandidateID, filePath, fileName, fileType, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully added image to asset candidate");
    }
    else
    {
        Debug.Log("Error adding image to asset candidate");
    }
});

Remove files from the Asset candidate

int assetCandidateID = 12;
int fileID = 1;
LootLockerSDKManager.RemovingFilesFromAssetCandidates(assetCandidateID, fileID, (response) =>
{
    if (response.success)
    {
      Debug.Log("Successfully removed file from asset candidate");
    }
    else
    {
      Debug.Log("Error removing file from asset candidate");
    }
});

Update or add data to the asset candidate

bool isCompleted = false;
// When updating an asset, all properties are optional.
// Empty fields are also updated, only update the ones that you want to replace
string name = "New Name"; // Optional
Dictionary<string, string> kv_storage = new Dictionary<string, string>();
kv_storage.Add("key", "value"); // Optional
Dictionary<string, string> filters = new Dictionary<string, string>();
filters.Add("key", "value"); // Optional
Dictionary<string, string> data_entities = new Dictionary<string, string>();
filters.Add("data", "name"); // Optional
int context_id = -1; // Optional
LootLockerSDKManager.UpdatingAnAssetCandidate(asset_candidate_id, isCompleted, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully updated asset candidate with ID: " + response.asset_candidate.id);
    }
    else
    {
        Debug.Log("Error updating asset candidate");
    }
}, name, kv_storage, filters, data_entities, context_id);

When you are satisfied with the changes to the asset candidate, you simply call the UpdatingAnAssetCandidate() function again, and change the isCompleted bool to true and the asset candidate will then be promoted to a UGC asset to be viewed by all your players.

Conclusion

In this How-to, we’ve created a UGC asset candidate, added some information to it and promoted it to an asset. If UGC moderation is enabled in your game, the newly generated asset will show up in the UGC moderation tab in the web console for you to take action on, and otherwise it will be available instantly to all your players by using any of the ListAssets() functions. With UGC it can also be a good idea to add a way for players to report the created content.

Last updated