question

kennyroy avatar image
kennyroy asked

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?

entities
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Seth Du avatar image
Seth Du answered

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.

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

kennyroy avatar image kennyroy commented ·

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?

1 Like 1 ·
kennyroy avatar image kennyroy commented ·

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.

0 Likes 0 ·
kennyroy avatar image kennyroy commented ·

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

0 Likes 0 ·
kennyroy avatar image kennyroy commented ·

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?

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ kennyroy commented ·

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.

0 Likes 0 ·
Cuong Pham avatar image
Cuong Pham answered

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!

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Seth Du avatar image Seth Du ♦ commented ·

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:

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]