Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Cloudcode not executing from event triggers.

Discussion in 'Cloud Code' started by MatureThemes, Apr 26, 2024.

  1. MatureThemes

    MatureThemes

    Joined:
    Mar 30, 2020
    Posts:
    2
    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:

    Code (CSharp):
    1. using Microsoft.Extensions.DependencyInjection;
    2. using Microsoft.Extensions.Logging;
    3. using Unity.Services.CloudCode.Core;
    4. using Unity.Services.CloudCode.Apis;
    5. using Unity.Services.CloudCode.Shared;
    6. using Unity.Services.CloudSave.Model;
    7. using System.Threading.Tasks;
    8. using System.Collections.Generic;
    9. using System;
    10. using Unity.Services.Economy.Api;
    11. using Unity.Services.Economy.Model;
    12. using static System.Formats.Asn1.AsnWriter;
    13.  
    14. namespace PlayerManagement
    15. {
    16.     public class NewPlayerSetup
    17.     {
    18.         private const string HangarSlotCount_Key = "HANGAR_SLOT_COUNT";
    19.         private const int DefaultHangarSize = 5;
    20.  
    21.         private readonly ILogger<NewPlayerSetup> _logger;
    22.  
    23.         public NewPlayerSetup(ILogger<NewPlayerSetup> logger)
    24.         {
    25.             _logger = logger;
    26.         }
    27.  
    28.         [CloudCodeFunction("InitializeNewPlayer")]
    29.         public async Task InitializeNewPlayer(IExecutionContext ctx, IGameApiClient gameApiClient, string playerId)
    30.         {
    31.             try
    32.             {
    33.                 var response = await gameApiClient.CloudSaveData.GetItemsAsync(ctx, ctx.ServiceToken, ctx.ProjectId, playerId, new List<string>() { HangarSlotCount_Key });
    34.                 if (response.Data.Results.Count == 0)
    35.                 {
    36.                     await gameApiClient.CloudSaveData.SetItemBatchAsync(ctx, ctx.ServiceToken, ctx.ProjectId, playerId,
    37.                         new SetItemBatchBody(new List<SetItemBody> { new(HangarSlotCount_Key, DefaultHangarSize) }));
    38.  
    39.                     _logger.LogInformation("The player's hangar has been initialized.");
    40.  
    41.                 }
    42.             }
    43.             catch (ApiException e)
    44.             {
    45.                 _logger.LogError("Failed to initialize player data in Cloud Save. Error: {Error}", e.Message);
    46.                 throw new Exception($"Failed to initialize {playerId} data in Cloud Save. Error: {e.Message}");
    47.             }
    48.         }
    49.  
    50.         [CloudCodeFunction("GiftStarterVehicles")]
    51.         public async Task GiftStarterVehicles(IExecutionContext ctx, IGameApiClient gameApiClient, string playerId)
    52.         {
    53.             try
    54.             {
    55.                 var configResponse2 = await gameApiClient.EconomyConfiguration.GetPlayerConfigurationAsync(ctx, ctx.ServiceToken, ctx.ProjectId, playerId);
    56.                 AddInventoryRequest gift = new AddInventoryRequest("GLD_0200");
    57.                 var response2 = await gameApiClient.EconomyInventory.AddInventoryItemAsync(ctx, ctx.ServiceToken, ctx.ProjectId, playerId, gift);
    58.                 _logger.LogInformation("Successfully gifted vehicle.");
    59.             }
    60.             catch (ApiException e)
    61.             {
    62.                 _logger.LogError(e, "Failed to gift starter vehicle");
    63.                 throw new Exception($"Failed to initialize {playerId} data in Cloud Save. Error: {e.Message}"); ;
    64.             }
    65.             try
    66.             {
    67.                 AddInventoryRequest gift2 = new AddInventoryRequest("GLD_0100");
    68.                 var response3 = await gameApiClient.EconomyInventory.AddInventoryItemAsync(ctx, ctx.ServiceToken, ctx.ProjectId, playerId, gift2);
    69.                 _logger.LogInformation("Successfully gifted vehicle.");
    70.             }
    71.             catch (ApiException e)
    72.             {
    73.                 _logger.LogError(e, "Failed to gift starter vehicle");
    74.                 throw new Exception($"Failed to initialize {playerId} data in Cloud Save. Error: {e.Message}"); ;
    75.             }
    76.         }
    77.     }
    78.  
    79.     public class ModuleConfig : ICloudCodeSetup
    80.     {
    81.         public void Setup(ICloudCodeConfig config)
    82.         {
    83.             config.Dependencies.AddSingleton(GameApiClient.Create());
    84.         }
    85.     }
    86. }
    87.  
    And here are my trigger configs. I reconciled and re-deployed through CLI and have double checked the environments for everything.

    Code (CSharp):
    1. {
    2.   "$schema": "https://ugs-config-schemas.unity3d.com/v1/triggers.schema.json",
    3.   "Configs": [
    4.     {
    5.       "Name": "initialize-new-player",
    6.       "EventType": "com.unity.services.player-auth.signed-up.v1",
    7.       "ActionUrn": "urn:ugs:cloud-code:PlayerManagement/InitializeNewPlayer",
    8.       "ActionType": "cloud-code"
    9.     },
    10.  
    11.     {
    12.       "Name": "gift-starter-vehicles",
    13.       "EventType": "com.unity.services.player-auth.signed-up.v1",
    14.       "ActionUrn": "urn:ugs:cloud-code:PlayerManagement/GiftStarterVehicles",
    15.       "ActionType": "cloud-code"
    16.     }
    17.   ]
    18. }
    19.  
    20.  
    Any help would be much appreciated!
     
  2. KM6611

    KM6611

    Joined:
    Jun 27, 2018
    Posts:
    11
    I have the same problem.

    A trigger that was working fine until yesterday is not working starting today.
     
  3. unity_Ctri

    unity_Ctri

    Unity Technologies

    Joined:
    Oct 20, 2020
    Posts:
    83
    Hi everyone,

    Just to let you know we've confirmed the issue and are actively working to resolve it.
    There's a notice in the Unity Dashboard that will include any relevant updates, and will disappear once everything is resolved.
     
    GabKBelmonte and kitkat514 like this.
  4. unity_Ctri

    unity_Ctri

    Unity Technologies

    Joined:
    Oct 20, 2020
    Posts:
    83
    Update on the above - fixed.
    Also pleased to report that we've been able to ensure that any triggers that weren't executed between then and now, have been retroactively processed!

    Thanks for everyone's patience and understanding
     
    GabKBelmonte and kitkat514 like this.
  5. MatureThemes

    MatureThemes

    Joined:
    Mar 30, 2020
    Posts:
    2
    Thanks a bunch Ctri! o7
     
    GabKBelmonte likes this.