question

Moses avatar image
Moses asked

Unity GetPlayerSegmentsRequest

How does the GetPlayerSegmentsRequest work in Unity ?

10 |1200

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

1 Answer

·
JayZuo avatar image
JayZuo answered

In Client API,GetPlayerSegmentsRequest usually used in GetPlayerSegments method to get all segments that a player currently belongs to at this moment in time. In Unity, you can use it like the following:

PlayFabClientAPI.GetPlayerSegments(new GetPlayerSegmentsRequest(),
    (result) =>
    {
        foreach (var segment in result.Segments)
        {
            Debug.Log(segment.Id + " : " + segment.Name);
        }
    },
    (error) =>
    {
        Debug.LogError(error.GenerateErrorReport());
    });

If you are using Server API, then it's similar to the Client API, the only difference is that you will need specify the PlayFabId in PlayFab.server.Models.GetPlayersSegmentsRequest like:

PlayFabServerAPI.GetPlayerSegments(new PlayFab.ServerModels.GetPlayersSegmentsRequest { PlayFabId = "xxxxx" },
    (result) =>
    {
        foreach (var segment in result.Segments)
        {
            Debug.Log(segment.Id + " : " + segment.Name);
        }
    },
    (error) =>
    {
        Debug.LogError(error.GenerateErrorReport());
    });

While in Client API, it's always using the player that currently logged in, so there is no need to provide the PlayFabId.

4 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.

Moses avatar image Moses commented ·

Thanks Jay for your quick response,

I am new to Play fab, currently on an Rnd task trying to figure out if we can use it for an upcoming project.I am attempting to store the players geographical location (preferably their neighbourhood) an then I would like to show the current user all the other users in his/her area, so maybe do a scan of their profiles for a KPV? any ideas ?

0 Likes 0 ·
brendan avatar image brendan Moses commented ·

That's not something we can support in our current data models, as you would need to have the ability to update and query that single data store by a large number of users, potentially. Groups can manage data that's shared by typical clan/team/guild groupings (100 players or so), but a system that lets thousands of players all read and update a generic shared data store is not something we provide, due to the high cost of such a system. We do plan to provide geo-based functionality in future, however. Keep an eye on our blog for more information on this.

0 Likes 0 ·
Moses avatar image Moses commented ·

Hi Brendon, many thanks for your response.

Before we look elsewhere, I just want to clarify things to ensure we're on the same page... as we'd love to use PlayFab for this project. (...and I may have confused things by presuming this would be approached using segments and actual geodata)

The use-case here is for each individual player to be able to see a top-5 list of other players who share a similar parameter (in this case probably a fairly static ID representing their chosen physical location), and see some custom data about each of those players (e.g. their username and current XP level).

To me this doesn't sound much more than a typical leaderboard system.

Thanks! Moses.

0 Likes 0 ·
brendan avatar image brendan Moses commented ·

It is, for a leaderboard system that includes the ability to filter on geolocation. We do not currently support that, but it is in our roadmap for upcoming work. And that's specifically what I'm highlighting: You'll have this built-in with PlayFab when we update for the additional filtering mechanisms on leaderboards (date TBD, but we'll announce it as soon as we can). Before that, we do not support this, as you need a data space that allows all players to aggregate information collectively, and with high consistency. There isn't a generic data store that allows for that due to the high cost.

The alternative in the immediate would be to have a separate statistic for each region, and have players report their stats only to the leaderboard for their region. That has obvious drawbacks, which is why I was suggesting either waiting on our update, or using an external data store.

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.