question

Joshua Williams avatar image
Joshua Williams asked

(Unreal Blueprint) Help with json arrays and objects

I'm very new with using json and have been primarily referencing the api doc to cobble together what calls I should be using.

My question is how can I "break apart" json objects to get the information I'm trying to call?

The screenshot is a basic example of what I'm stuck on right now. (I know it deals with an array, but am hoping any help I get would lead into how to use the objects contained in the array.)


I have a project in which the player can create up to 3 characters under their title account. When the player logs in, I'd like the client to check if there are characters on the account and if not, load a character creation system. If there are characters present, then to assign the characterid and charactername values to individual buttons. I know this info is contained in the CharacterData result, but accessing it is the issue.

The above blueprint executes as intended and prints the "Data Loaded" string. But when I try to do anything else regarding the Result Characters or Response Data, neither the DataLoaded or DataFailed events fire.

I know similar questions have been posted and I've tried implementing some ideas from those threads but still nothing. Hoping someone can shed some light for me.

getusersbp.png (101.4 KiB)
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.

Joshua Williams avatar image Joshua Williams commented ·

Sorry, but I forgot to also add that there is a character on the account, with a characterid and unique name. So I know the issue isn't not having any characters to pull from.

0 Likes 0 ·

1 Answer

·
Turner avatar image
Turner answered

PlayFab's blueprints can be hard to learn because of the limited documentation. So, I made a little example Blueprint that I hope will be helpful to you.

The goal of this example is to print out the EntityKeyID of the logged in player. I know I can get the data I need from the result of the LoginWithCustomID call, so I'm going to start there.

My first step is going to be caching the login result like this:

Any time you are going to be working with JSON within PlayFab, you will almost always need to have the PlayFab docs open in the background to use as a reference.

That LoginData struct contains the following data (taken from the docs):

EntityToken If LoginTitlePlayerAccountEntity flag is set on the login request the title_player_account will also be logged in and returned.
InfoResultPayload Results for requested info.
LastLoginTime
  • string
The time of this user's previous login. If there was no previous login, then it's DateTime.MinValue
NewlyCreated
  • boolean
True if the account was newly created on this login.
PlayFabId
  • string
Player's unique PlayFabId.
SessionTicket
  • string
Unique token authorizing the user and game at the server level, for the current session.
SettingsForUser Settings specific to this user.
TreatmentAssignment The experimentation treatments for this user at the time of login.

As we can see, our login struct has the EntityToken which is of the type EntityTokenResponse, that is our JSON Object.

If we look at the docs for an EntityTokenResponse we can see it holds the following data:

Entity The entity id and type.
EntityToken
  • string
The token used to set X-EntityToken for all entity based API calls.
TokenExpiration
  • string
The time the token will expire, if it is an expiring token, in UTC.

Our ID is inside that EntityKey.

So, finally, here is the Blueprint for getting the EntityKey ID:

GetObjectField returns the Value for the given Field Name as a JSON object. In this case we are searching the EntityTokenResponse for a field called "Entity".

GetStringField does the same thing, except it returns it as a string. There we are searching the "Entity" field, for a field called "ID" which gives us our result.

If you want to learn more, I encourage you to go inside of a blueprint, right click in open space, disable "Context Sensitive", and enter "PlayFab JSON" into the search bar. You will get a list of the different JSON functions and honestly the best way to learn them is by simply trying them out.

I hope I was able to get you on the right track with this little guide here. This was more of a general guide, but if you have more specific questions, let me know!


getentityid.png (127.5 KiB)
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.

Joshua Williams avatar image Joshua Williams commented ·

@Turner Thank you so much for the amazing response!

I've had some progress since I posted the original question, but your reply has cleared up a few grey areas. (Especially the trick about caching the results. That will definitely clean the spaghetti code that is blueprints)

I also agree with you, having the docs on a second screen while playing with playfab json nodes is a great way to peice together what I need. It's been working so far.

1 Like 1 ·
Turner avatar image Turner Joshua Williams commented ·

Glad to hear it!

1 Like 1 ·
Joshua Williams avatar image Joshua Williams Turner commented ·

Ok, so now I've gotten the hang of working with PlayFab json, my next big hurdle is updating data with groups of entries.

I can successfully add a single key/value to a character or player account, but I was wondering the method for doing multiple key values at one time. Say on a new character created, automatically add the keys "Health", "Energy" and "Armor", and setting them to "100", "75", "30", respectively.

Or would this be better suited for cloud script? (For what it's worth, I'd prefer to keep it in blueprints if possible. Cloud Script is a whole other level for me)

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.