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?
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.
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.
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?
Is it because this in a playfab player id being passed by cloudscript and not the title_player_id?
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?
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.
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!
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:
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