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

Question (economy) Virtual purchases from cloud code

Discussion in 'Cloud Code' started by FabrizioRagaglia, Mar 28, 2024.

  1. FabrizioRagaglia

    FabrizioRagaglia

    Joined:
    Apr 19, 2021
    Posts:
    4
    Hello, I am working on a multiplayer game with mirror and ugs.
    I am developing a shop and I need the server to obtain all the possible products for the player (virtual economy purchases) through cloud code.
    This is possible? Because the only thing I find is being able to access the player's inventory but not the products available for purchase.

    can cloud code connect with economy and obtain virtual purchasing?
     
  2. GabKBelmonte

    GabKBelmonte

    Unity Technologies

    Joined:
    Dec 14, 2021
    Posts:
    149
    Hi!

    I'm from the dev experience team, let me try to help you out here.

    Are you using C# or JS?

    Each service has 2 APIs, the runtime API that is used by clients, and the admin API that is used by the dashboard, editor, etc, for configuring the services.

    Will raise that question up with the team, looking at the APIs documentation looks like the Economy Client API does not have than info, the admin API does: https://services.docs.unity.com/economy-admin/v2/#tag/Economy-Admin/operation/getPublishedResources. You'll need a service account that can be set up from the dashboard.

    I see 4 options:
    1. Call that endpoint from your Cloud Code using service account. Use Caching if possible as the rate limits on admin APIs are way stricter.
    2. I describe here how to generate a client from specs. You can generate one for the admin API instead of the runtime API.
    options 1 and 2 are slightly technical and need a lil work, but the CLI has code that shows how its used.
    3. Hardcode your purchases into your Cloud Code Script. I know this is not ideal, but might be good enough in the short term.
    4. Wait for a feature update from the team.

    If you're using Cloud Code Modules, option 1 or 2 with caching is probably the best bet.

    Ill see what the service teams think :)

    Cheers!
     
  3. anthonylord

    anthonylord

    Unity Technologies

    Joined:
    Dec 8, 2022
    Posts:
    8
    Hello, the Economy cloud code module should allow you to get all available purchases for the player.

    All resources, including possible purchases, are returned from the getPlayerConfiguration endpoint.
    Just pass the playerID along to your cloud code script.

    The PlayerID is needed because you might have Game overrides on the purchase rewards which would change what is returned for that player.
     
  4. FabrizioRagaglia

    FabrizioRagaglia

    Joined:
    Apr 19, 2021
    Posts:
    4
    Great thanks, I was able to access all the information I needed through the getPlayerConfiguration.