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 Scheduled Events or C# Module?

Discussion in 'Cloud Code' started by Kurutah, Apr 5, 2024.

  1. Kurutah

    Kurutah

    Joined:
    Jul 19, 2017
    Posts:
    11
    In my game, there are contests that other players vote on. Players can vote for randomly selected contests, primarily for those who received fewer votes - some additional minor logic regarding this is also implied. These contests are supposed to end over time. Participants can be online or offline at the end of the contest; if they are offline, they should receive a notification the next time they log into the game.

    If I understood correctly from reading the documentation, to close the contests and distribute rewards, I need to use Schedule events.

    Or is it possible to use a C# module that will initiate a timer, close the contests upon its completion, and thus avoid using Schedule events (I haven’t figured out if this is possible)?

    Please clarify: Which of these options is possible? Which is more practical? Thank you.
     
    Last edited: Apr 5, 2024
  2. samg-unity

    samg-unity

    Unity Technologies

    Joined:
    Mar 23, 2021
    Posts:
    45
    Hi @Kurutah - Scheduling an event to trigger a C# module function at the close of the contest is currently poossible. You should be able to follow the New year sample here https://docs.unity.com/ugs/en-us/ma...se_case_sample:_Wish_players_a_happy_new_year to achieve the behaviour you are after.

    Attempting to use a C# module to initiate a timer would not be a good option as we can't guarantee the C# module resource will be available and running for the lifetime of the timer.
     
    Kurutah likes this.
  3. Kurutah

    Kurutah

    Joined:
    Jul 19, 2017
    Posts:
    11
    Thank you for your response. Could you possibly show me the principle (or provide a link to the documentation) on how to save active users and work with them, preferably (excluding schedules) through C# modules?

    I’ve spent many hours reading the documentation and studying examples, but all the methods I try either don’t work, are outdated, or relate to the Player and save data in their field - but I need a separate list that players can populate with their data (by entering a contest), vote (by downloading and modifying something in the list), and receive rewards when their entry is winning. That is, participants do not know the IDs of other players when using this list; they simply receive it and vote.

    It seems that the documentation mentions “Game Data” which could be suitable for storing player IDs and information about their contests. However, I’m uncertain as I haven’t found any practical examples of how to manipulate this data using C#.

    "Game clients can only read custom items. They cannot create, modify or delete Custom items. Custom Items can be written to using Cloud Code, a game server, using the HTTP API or from the Unity Cloud Dashboard." - from docs.

    Alternatively, as I considered later, should I be using Cloud Save Queries to handle this aspect?

    But anyway, I also would like to manage a list of player clones who have previously participated in contests, to compare with a clone of a player of a corresponding level during voting. How should I manage and work with such a list of clones? Is there a specific Unity service or pattern that would allow me to implement this feature?

    Thank you.
     
    Last edited: Apr 10, 2024
  4. samg-unity

    samg-unity

    Unity Technologies

    Joined:
    Mar 23, 2021
    Posts:
    45
    > Could you possibly show me the principle (or provide a link to the documentation) on how to save active users and work with them, preferably (excluding schedules) through C# modules?

    Would you be able to expand on the question further? I'm not sure what you mean by "saving active users" and working with them e.g. what type of operations would you like to do?

    > I need a separate list that players can populate with their data (by entering a contest), vote (by downloading and modifying something in the list), and receive rewards when their entry is winning

    Have you considered the leaderboards service https://docs.unity.com/ugs/en-us/manual/leaderboards/manual/leaderboards? It sounds like it would facilitate this use case and you are able to associate additional metadata to entries.

    > Additionally, I would like to manage a list of player clones who have previously participated in contests, to compare with a clone of a player of a corresponding level during voting

    The leaderboards service can provide archives of leaderboards scores either paginated https://services.docs.unity.com/lea...rboards/operation/getLeaderboardVersionScores or by player https://services.docs.unity.com/lea...ds/operation/getLeaderboardVersionPlayerScore.

    If the leaderboards service would not suit your needs, then the combination of using Cloud Save Game Data with indexed fields which you can query could help.

    I can point you in the direction of the leaderboards Cloud Code sample https://docs.unity.com/ugs/en-us/manual/leaderboards/manual/access-cloud-code-csharp but unforuntately we don't currently have any up to date samples using the Cloud Save Game Data and queries. However the latest Cloud Save SDK should follow the Data API https://services.docs.unity.com/cloud-save/#tag/Data so will have methods available to get Game (Custom) Data and run queries e.g. The current Cloud Save sample https://docs.unity.com/ugs/en-us/ma...ides/unity-services-integration#Usage_Example could be expanded upon with the following

    Code (CSharp):
    1.             await gameApiClient.CloudSaveData.SetCustomItemAsync(...);
    2.             await gameApiClient.CloudSaveData.QueryPrivateCustomDataAsync(...);
    3.             await gameApiClient.CloudSaveData.QueryDefaultCustomDataAsync(...);
     
  5. Kurutah

    Kurutah

    Joined:
    Jul 19, 2017
    Posts:
    11
    The general principle is as follows: some players send one (or several) contestants to competitions. Other players will vote for these contests. I’m not planning to strictly monitor cheating protection in this game since multiplayer is just an addition to the single-player game, so players will store their data in JSON format on their local computers and use UGS primarily for conducting contests.

    I need a practical method to:

    • Allow other players to access data about current contestants and vote for them. - If I understand correctly, Cloud Save Queries would be best suited for this? Is it okay if there are (hypothetically) 100 000 players in the database, but only about 100 active contests? I’m asking because it sounds like sifting through a large number of players for those participating in contests seems like costly work - and it would be easier to have a separate list tied to player IDs - but I’m not sure if it's really costly and how to have a separate list :)
    • Maintain an additional ‘bots’ list, which is periodically updated with copies of actual contest participants to keep it current. This list, sorted by rating, will be used in voting so that voters are always presented with a choice between a real player and a ‘bot’ with a comparable rating (allowing voting to commence immediately without waiting for another player of a matching rating to become available).
    I hope I’ve explained the principle. What concerns me is when the methods I come across in training are marked as outdated, or I see examples in JavaScript with which I have no experience. But I will continue to figure it out if I’m confident that I’ve at least chosen the right services.

    After your response, I started considering the use of Leaderboards as well. However, I would still like to understand what to focus on specifically…

    Thank you.
     
    Last edited: Apr 10, 2024
  6. samg-unity

    samg-unity

    Unity Technologies

    Joined:
    Mar 23, 2021
    Posts:
    45
    No problem, I've asked if someone from the Cloud Save/ Leaderboards team could take a look at your use case and suggest which solution would be appropriate to focus on. In the mean time could you point me in the direction of the problem examples/ samples so I can flag those to get updated.

    Thanks!
     
    Kurutah likes this.