Hey all
Yesterday I managed to get a new-player-initialization CloudCodeFunction working that fired off the player-auth.signed-up event and I could validate the results through the dashboard. However after making a few changes this morning it seems that the Cloudcode is not running at all, even after reverting the changes. No logs to check and no keys saved to cloud data.
I am fairly new to UGS so there is a good chance I am missing something.
Here is my Cloudcode:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Unity.Services.CloudCode.Core;
using Unity.Services.CloudCode.Apis;
using Unity.Services.CloudCode.Shared;
using Unity.Services.CloudSave.Model;
using System.Threading.Tasks;
using System.Collections.Generic;
using System;
using Unity.Services.Economy.Api;
using Unity.Services.Economy.Model;
using static System.Formats.Asn1.AsnWriter;
namespace PlayerManagement
{
public class NewPlayerSetup
{
private const string HangarSlotCount_Key = "HANGAR_SLOT_COUNT";
private const int DefaultHangarSize = 5;
private readonly ILogger<NewPlayerSetup> _logger;
public NewPlayerSetup(ILogger<NewPlayerSetup> logger)
{
_logger = logger;
}
[CloudCodeFunction("InitializeNewPlayer")]
public async Task InitializeNewPlayer(IExecutionContext ctx, IGameApiClient gameApiClient, string playerId)
{
try
{
var response = await gameApiClient.CloudSaveData.GetItemsAsync(ctx, ctx.ServiceToken, ctx.ProjectId, playerId, new List<string>() { HangarSlotCount_Key });
if (response.Data.Results.Count == 0)
{
await gameApiClient.CloudSaveData.SetItemBatchAsync(ctx, ctx.ServiceToken, ctx.ProjectId, playerId,
new SetItemBatchBody(new List<SetItemBody> { new(HangarSlotCount_Key, DefaultHangarSize) }));
_logger.LogInformation("The player's hangar has been initialized.");
}
}
catch (ApiException e)
{
_logger.LogError("Failed to initialize player data in Cloud Save. Error: {Error}", e.Message);
throw new Exception($"Failed to initialize {playerId} data in Cloud Save. Error: {e.Message}");
}
}
[CloudCodeFunction("GiftStarterVehicles")]
public async Task GiftStarterVehicles(IExecutionContext ctx, IGameApiClient gameApiClient, string playerId)
{
try
{
var configResponse2 = await gameApiClient.EconomyConfiguration.GetPlayerConfigurationAsync(ctx, ctx.ServiceToken, ctx.ProjectId, playerId);
AddInventoryRequest gift = new AddInventoryRequest("GLD_0200");
var response2 = await gameApiClient.EconomyInventory.AddInventoryItemAsync(ctx, ctx.ServiceToken, ctx.ProjectId, playerId, gift);
_logger.LogInformation("Successfully gifted vehicle.");
}
catch (ApiException e)
{
_logger.LogError(e, "Failed to gift starter vehicle");
throw new Exception($"Failed to initialize {playerId} data in Cloud Save. Error: {e.Message}"); ;
}
try
{
AddInventoryRequest gift2 = new AddInventoryRequest("GLD_0100");
var response3 = await gameApiClient.EconomyInventory.AddInventoryItemAsync(ctx, ctx.ServiceToken, ctx.ProjectId, playerId, gift2);
_logger.LogInformation("Successfully gifted vehicle.");
}
catch (ApiException e)
{
_logger.LogError(e, "Failed to gift starter vehicle");
throw new Exception($"Failed to initialize {playerId} data in Cloud Save. Error: {e.Message}"); ;
}
}
}
public class ModuleConfig : ICloudCodeSetup
{
public void Setup(ICloudCodeConfig config)
{
config.Dependencies.AddSingleton(GameApiClient.Create());
}
}
}
And here are my trigger configs. I reconciled and re-deployed through CLI and have double checked the environments for everything.
{
"$schema": "https://ugs-config-schemas.unity3d.com/v1/triggers.schema.json",
"Configs": [
{
"Name": "initialize-new-player",
"EventType": "com.unity.services.player-auth.signed-up.v1",
"ActionUrn": "urn:ugs:cloud-code:PlayerManagement/InitializeNewPlayer",
"ActionType": "cloud-code"
},
{
"Name": "gift-starter-vehicles",
"EventType": "com.unity.services.player-auth.signed-up.v1",
"ActionUrn": "urn:ugs:cloud-code:PlayerManagement/GiftStarterVehicles",
"ActionType": "cloud-code"
}
]
}
Any help would be much appreciated!