question

James McGhee avatar image
James McGhee asked

Entity Groups and Entity Key

Not finding the answer in the documentaiton or perhaps I have my head screwed on wrong around Entity Group.

We had planned to use Entity Group to persist 'sessions' ... a sessions in our case is a simi-perminent group of players that have some shared data such as the location of objects in a world, etc. Our users can create a new session and this spins up a new server instance, they can then invite other players to the session and there they can build things together. A player can be a member of multiple sessions (we will throttle this of course). All players can log off and the sessions will shut down its server but its state is persisted such that when a player comes back online they can jump back into that shared world.

The Plan:

So the flow for a user to jump into the game is to login (that is authenticate via PlayFab)

Then we pull the list of sessions (aka Entity Groups) this user is a member of and offer the player the ability to create a new session (aka Entity Group).

A related Entity Object on the Group would understand the state of any allocated server for the session/world. That is when all users are disconnected we will shut down the related server, when one logs back on and wants to connect to an existing 'session' (load the data stored in the Entity Group on an Entity File) we allocate a server and update the conneciton info on the Entity Group via an Entity Object.

This means we need to be able to query the list of Entity Groups a user is part of right after log in... the user is not yet connected to a multiplayer session and is still sitting in the menu. I can see that the ListMembershipRequest has a field for Entity (EntityKey) and the examples I have seen in documentation use that only; not the AuthenticationContext. I haven't really understood Entity in respect to expressing the player as an entity, the only reference I have seen to such is in Party.

So are we going about it all wrong or just not understanding how to get a list of all Entity Groups a player is part of?

entities
3 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.

James McGhee avatar image James McGhee commented ·

[Edit]

Found this
https://community.playfab.com/questions/34738/no-logintitleplayeraccountentity-to-set-in-unity-s.html

So it seems this flag is hidden and defaulted to true so EntityToken should always be there ... it would be a great idea to update the documentaiton on all the login methods to note that EntityToken is always present. Given that I think I know how to get the users Entity ID now ... so I should be able to list the Entity Group's assoceated with it?

0 Likes 0 ·
James McGhee avatar image James McGhee James McGhee commented ·

[Moved comment]

0 Likes 0 ·
James McGhee avatar image James McGhee commented ·

Still struggling with this based on what I see in the documentation.

ListMembershipRequest has a field Entity of type EntityKey ... I have an EntityKey from LoginRequest ... they are not the same type :(

PlayFab.ClientModel.EntityKey
vs
PlayFab.GroupModel.EntityKey

They look structurally identical but I assume there is a reason why you defined that class twice with the same name in two different namespaces?

[Edit]

Looks like EntityKey is defined ... ALOT ... (found 1 in AdminModel as well) in your Unity SDK ... is this an error or is there some reason that I am missing?

Which should I use? are they interchangable? Is it even possible to fetch the EntityGroup's assoceated with a player ...or even possible to assoceate EntityGroups with a player?

0 Likes 0 ·

1 Answer

·
Rick Chen avatar image
Rick Chen answered

Apart from Parties, Entity Groups can also serve other purpose like Clans/Guilds, Chat Channels and In-Game subscription to information. You may refer to Entity groups.

ListMembershipRequest does not require the EntityKey, you can leave it empty. Once a player is logged in, the SDK will save the entity token of the player in your game, and ListMembership use this token to identify the player.

Entities are the most basic addressable "things" that PlayFab APIs operate on. An EntityKey contains a Type and an Id which together uniquely identify the Entity. There are several build-in entity types such as “title”, “title_player_account”, you can refer to Available built-in entity types. “PlayFab.ClientModel.EntityKey” and “PlayFab.GroupModel.EntityKey” can both refer to the same entity. “PlayFab.ClientModel.EntityKey” are defined so that you can acquire the EntityKey using client Login APIs. “PlayFab.GroupModel.EntityKey” are defined because some Entity Group APIs may use it in its request body.

>> how to get a list of all Entity Groups a player is part of after player login?

You can use ListMembership in the successful callback of the Login Function you used. For example:

public void LoginWithEmailAndPassword(string email, string password)
{
PlayFabClientAPI.LoginWithEmailAddress(new LoginWithEmailAddressRequest()
{
TitleId = PlayFabSettings.TitleId,
Email = email,
Password = password
},
OnLoginSuccessful,
null //your error callback here
);
}
public void OnLoginSuccessful(LoginResult login_result)
{
PlayFabGroupsAPI.ListMembership(new PlayFab.GroupsModels.ListMembershipRequest { }, (PlayFab.GroupsModels.ListMembershipResponse response)=>
{
Debug.Log(response);
}
, null //your error callback here
);
}

>> Is it possible to associate EntityGroups with a player?

There are several ways to associate an Entity Group with a player, you can use one of them blow:

  1. AddMembers API
  2. InviteToGroup and AcceptGroupInvitation APIs
  3. ApplyToGroup and AcceptGroupApplication APIs

You can refer to this document Groups to see the available group APIs.

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.

James McGhee avatar image James McGhee commented ·

Thank you I was slowly pulling something like that together but was confused by some of the documentation around Entity. The system seems like exactly what we need just a bit of a learning curve.

//Assume LocalUser.Entity is the EntityKey of the logged in user as read from the LoginResult.EntityToken

var request = new CreateGroupRequest { GroupName = groupName, Entity = new PlayFab.GroupsModels.EntityKey { Id = LocalUser.Entity.Id, Type = LocalUser.Entity.Type } };
            PlayFabGroupsAPI.CreateGroup(request, 
                (result) =>
                {
			//TODO: Do Work on success
                }, 
                (error) =>
                {
			//TODO: Do Work on failure
                });
        }

Would the above produce a group that already had an admin member of the LocalUser or no? such that I still need to add the local user as a member of said group in which case I need to read more.

In the above I am assuming the various EntityKey structures are interchangeable so I am simply building an GroupsModels.EntityKey based on the info in the ClientMode.EntityKey ... still not sure that is correct.

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.