• Sign Up Login
  • Features
    • Game Services
    • Real-time Analytics
    • LiveOps
    • Add-ons
  • Game Services
  • Real-time Analytics
  • LiveOps
  • Add-ons
  • Games
  • Pricing
  • Blog
  • Support
    • Docs
    • Forums
    • Contact
  • Docs
  • Forums
  • Contact
  • Sign Up Login
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Ideas
    • Articles
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by kennyroy · Jul 16 at 01:48 AM · entities

Add players to Entity Groups automatically?

I am working on a very fringe-case game that requires everyone to be in an entity group at all times. How would I go about this?

With the REST API I see that one can use the AddMember POST to achieve this. I'm wondering why there is not a similar call in the Unity API? Or could I use CloudScript to fire this POST from a PlayStream Event on user created?

What would be your method?

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by SethDu · Jul 16 at 06:31 AM

What do you mean Unity API? Groups - Add Members API call is provided in Unity SDK and the thing you need to do is to enable Entity API in the Unity PlayFab extension.

Set up a Rule that will “call CloudScript Functions to fire this POST from a PlayStream Event on user created“ is feasible because user creation event is unique and only occurs once for each account.

In addition, what functionality you are asking for in the Group Feature? As if you are using the Segmentation, there is “All Players” entry by default.

Comment

People who like this

0 Show 5 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kennyroy · Jul 16 at 09:07 AM 0
Share

Sorry I'm a bit loose with the nomenclature. I'm also a bit new to all this, so I make some bad assumptions from time to time. I was thinking there was a fundamental difference between using the REST API and the Unity PlayFab SDK that meant I shouldn't use anything that is not in the Unity SDK. It feels a little awkward doing a POST when the entire rest of my game fires CloudScript from the C# Unity SDK.

As for what functionality, I need the roles and basic group membership. My game is very fringe-case in that the entire virtual location is based on what group you are in, and so players MUST be in a group to start. Sounds like we'll be able to use AddMembers, fired from CloudScript on PlayStream Events.

avatar image kennyroy · Aug 01 at 09:21 PM 0
Share

I copied some code from these forums and am firing from the playstream event "com.playfab.player_created"

handlers.addNewAccountToCompany = function (args, context) {
    var ID = "DA296B35A0BC7FD7";
    var group = { Id: ID, Type: "group" };
    var entityProfile = context.currentEntity;
    try {
        entity.AddMembers({ Group: group, Members: [entityProfile.Entity] });
    }
    catch (error) {
        log.error(error);
        return false;
    }
    return true;
}

but this does not work. Error just returns "Error". Can you guess as to why?

avatar image kennyroy · Aug 01 at 09:51 PM 0
Share

Is it because this in a playfab player id being passed by cloudscript and not the title_player_id?

avatar image kennyroy · Aug 01 at 10:04 PM 0
Share

Ahhh. seems like it. You have to add the player's title entity key to groups, no playfab entity. Ok, getting somewhere. I am going to try to just pull that with a

GetTitlePlayersFromMasterPlayerAccountIds

and see what happens. Is that the best call to make to get the player title ID from their playfab ID?

avatar image SethDu ♦ kennyroy · Aug 02 at 07:16 AM 0
Share

I believe you are right and the API you mentioned is a good solution. This is interesting, in fact the Master Player ID will stand for a master account within the studio(who will own multiple title accounts in different titles) and it's studio-unique, meanwhile title id is unique within the title. If you appoint a player in a title, title id will be more representative.

avatar image

Answer by Cuong Pham · Jul 16 at 12:21 PM

I also have the same problem when I try to add member to group. My function:

    public static void AddMemberToGroup(string groupId, string memberId)
    {
        PlayFabEntityAPI.AddMembers
        (
            new AddMembersRequest
            {
                Group = new EntityKey { Id = groupId, Type = EntityTypes.group, TypeString = EntityTypes.group.ToString() },
                Members = new List<EntityKey> { new EntityKey { Id = memberId, Type = EntityTypes.title_player_account, TypeString = EntityTypes.title_player_account.ToString() } }
            },
            (result) =>
            {
                Debug.Log("!!!!!!!!!!!!!");
            },
            (error) =>
            {
                Debug.Log(error.ErrorMessage);
            }
        );
    }

Error:

Only requests using a Title principal may directly add members to groups

Anyone did used AddMembers function please give me a sample code?

Thanks!

Comment

People who like this

0 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SethDu ♦ · Jul 17 at 01:50 AM 0
Share

This is because any user is not allowed to add members by default (Only Administrator who owns the title can do).

Things you can do are:

  • Change the Entity Policy to enable it. You may refer to: https://community.playfab.com/questions/23016/entity-api-group-methods-policy-error.html.
  • Get a title-level entity token, which is not recommended in your client because it is not safe and you have to input secret key in the header of GetEntityToken API http call.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    500 error on InitiateFileUploads 1 Answer

    Entities, Entity Groups and using them as persistent Data "containers" 1 Answer

    PlayFab create group playmaker action 0 Answers

    Saving single player game date in Entity files? 2 Answers

    NotImplementedException: The requested feature is not implemented. 0 Answers

    • PlayFab

      • Features
      • Games
      • Pricing
      • Blog
    • Engineers

      • Documentation
      • Quickstarts
      • API Reference
      • SDKs
      • Usage Limits
    • Support

      • Forums
      • Videos
      • Contact
      • Service Health
      • Terms of Service
    • Social

      • Facebook
      • Twitter
      • LinkedIn
      • YouTube
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • About Microsoft
    • Jobs
    • Accessibility
    • Diversity & inclusion
    • Security
    • Company news
    • © Microsoft 2019
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Post an idea
    • Create an article
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Ideas
    • Articles
    • Users
    • Badges