Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Unique Player Username

Discussion in 'Cloud Save' started by ChrisSmithLife, Aug 8, 2022.

  1. ChrisSmithLife

    ChrisSmithLife

    Joined:
    Jul 10, 2017
    Posts:
    2
    Hello,

    I am wanting to allow my players to enter a Unique Username after authenticating. I know I can easily save whatever string they provide in Cloud Save but I want to return an error if it is not unique. Is there a way to query by a key across all Player saved data so I can determine if the inputed username is already taken?

    This should absolutely be key functionality if there is not already a way to achieve this.

    Thank you so much!
    Chris
     
  2. SebT_Unity

    SebT_Unity

    Unity Technologies

    Joined:
    Jun 21, 2021
    Posts:
    268
    Hi Chris,
    Great question and thanks for posting on the forum.
    At this current time there isn't a way to verify cloud save data for other players.

    I will be adding your name to the feature request this is something that is on the roadmap.

    I will update this post as soon as I have more information

    NB: A potential workaround may be for CLOUD CODE to execute a query that would verify if a certain name exists. However I will verify with my colleagues if this is possible.
     
  3. ChrisSmithLife

    ChrisSmithLife

    Joined:
    Jul 10, 2017
    Posts:
    2
    Hello SebT,

    If there was a way to query with Cloud Code that would work perfect! But I don't see a way to do that in the documentation so any insights on if this is possible would be amazing.
     
  4. SebT_Unity

    SebT_Unity

    Unity Technologies

    Joined:
    Jun 21, 2021
    Posts:
    268
    Hi Chris,
    I've verified with my colleagues and unfortunately my potential suggestion mentioned above will not work. (Hope this will be possible in the future)
    I've added the feature request for Cloud Save. If the feature is developed and released I will update this post.
    I've also added a secondary feature request for querying cloud save data with cloud code and or Analytics.

    Wishing you all the best,
    Seb
     
  5. Kawa_13

    Kawa_13

    Joined:
    Jan 29, 2021
    Posts:
    5
    The same problem, for some reason I thought that it was possible with the cloud code((( Awaiting update....
     
  6. Kawa_13

    Kawa_13

    Joined:
    Jan 29, 2021
    Posts:
    5
    Leaderboards have the same problem?! How to check score All players??
     
  7. BayouSoftware

    BayouSoftware

    Joined:
    Oct 7, 2012
    Posts:
    15
    Just bumping this as its a joke there's no way to enforce unique usernames especially considering UGS is supposedly built by the team from Chilliconnect, yet the chilliconnect service had these capabilities (and leaderboards) but is now being shut down to focus on UGS.

    Its rather infuriating as a chilli customer how badly this has been handled.

    I want to use UGS but its just not a viable product yet.
     
  8. SebT_Unity

    SebT_Unity

    Unity Technologies

    Joined:
    Jun 21, 2021
    Posts:
    268
    Hi BayouSoftware,

    Thanks for the feedback. I've brought your concerns to various teams at Unity.
    We are trying to get most use cases and will work to get more solutions out to the everyone as soon as we can.
     
  9. VentaGames

    VentaGames

    Joined:
    Jul 9, 2021
    Posts:
    123
    Any updates on this?
     
  10. Sparklmonkey

    Sparklmonkey

    Joined:
    Apr 1, 2020
    Posts:
    3
    A work around I have found, is to use Leaderboards. As your user logs in, add them to a leaderboard. Then you can use Cloud Code to get all the Leaderboard entries to check there players saved data, as they return the Player ID and you can check the save data of the other players.
     
  11. unity_lKj2L45mNspniw

    unity_lKj2L45mNspniw

    Joined:
    Dec 20, 2019
    Posts:
    1
    IainUnity3D and SebT_Unity like this.
  12. francoisjjunity

    francoisjjunity

    Unity Technologies

    Joined:
    Nov 23, 2020
    Posts:
    29
    Hi all,

    You could also use the new Cloud Save queries feature to implement this feature for your game - https://docs.unity.com/ugs/en-us/manual/cloud-save/manual/concepts/queries. I would suggest you give the player-name management a try first to see if that solves your use case though.

    To do this, you would need to 1) create an index in cloud save and 2) save your player names in cloud save 3) use cloud code to query cloud save with the EQ operator on the created index.

    This is a brand new feature and there are a couple of caveats that you need to keep in mind:
    1. Only data saved after you've created the index can be queried
    2. This feature is currently only available through cloud code - we're still working on the Unity SDK

    Hope that helps!
     
  13. rainyblue99

    rainyblue99

    Joined:
    Jan 30, 2022
    Posts:
    1
    Hello francoisjjunity,

    I finished configuring playername as index in cloud save.
    And I want to query whether a specific playername exists through the QueryDefaultPlayerData function in cloud-code, but I can't find a related calling example.

    https://cloud-code-sdk-documentation.cloud.unity3d.com/cloud-save/v1.4

    Just looking at the API specification of the address above, I have no idea how to use it.. ㅠㅠ Could you provide a usage sample in the cloud code?
     
  14. francoisjjunity

    francoisjjunity

    Unity Technologies

    Joined:
    Nov 23, 2020
    Posts:
    29
    Hi rainyblue99,

    Here is a simple Cloud Code javascript example with some comments inline. Using Cloud Code C# would be similar to this example.

    Code (JavaScript):
    1. const { DataApi } = require("@unity-services/cloud-save-1.4");
    2.  
    3. module.exports = async ({ params, context, logger }) => {
    4.   const { projectId, playerId, accessToken } = context;
    5.   const cloudSaveApi = new DataApi({ accessToken: context.serviceToken });
    6.   // step 0: configure cloud code with a playerName parameter
    7.   const { playerName } = params;
    8.  
    9.   try {
    10.     // step 1: create the index on the "name" key for the "players" entity type and "default" access type in Cloud Save
    11.     // step 2: save the player name to cloud save
    12.     // await cloudSaveApi.setItem(projectId, playerId, {
    13.     //   key: "name",
    14.     //   value: playerName,
    15.     // });
    16.     // const playerResult = await cloudSaveApi.getItems(projectId, playerId);
    17.     // logger.info(playerResult.data);
    18.  
    19.     // step 3: do an "equals" query operator.
    20.     // The operator could be one of the following operators:
    21.     // * EQ - Equal
    22.     // * NE - Not Equal
    23.     // * LT - Less Than
    24.     // * LE - Less Than or Equal
    25.     // * GT - Greater Than
    26.     // * GE - Greater Than or Equal
    27.     const result = await cloudSaveApi.queryDefaultPlayerData(projectId, {
    28.       fields: [{
    29.         "key": "name",
    30.         "value": playerName,
    31.         "op": "EQ",
    32.         "asc": true
    33.       }],
    34.       returnKeys: ["name"]
    35.     });
    36.  
    37.     // step 4: do something with the query result, in this case, return it to the caller
    38.     return result.data;
    39.   } catch (err) {
    40.     logger.error("Error while calling out to Cloud Save", {"error.message": err.message});
    41.     throw err;
    42.   }
    43. };
     
    IainUnity3D likes this.