question

eswitzer07 avatar image
eswitzer07 asked

Unreal Blueprints: Working with Json

Fairly new to this sort of work, just looking for clarification on how to store and revive user data on the PlayFab servers.

For now Im looking to build out a basic XP / Level system inside unreal utilizing PlayFab. Im assuming I should be using the User Data Structures for this (As opposed to statistics). I have the following player data on the server:

This is my blueprint inside unreal to get the data, it seems to not throw an error message: http://puu.sh/zyJvC/a70aa05ac5.png however the returned values are 0.0

Whats the proper way to work with the Json data type inside unreal to allow it to be readable, and I guess more importantly writable by the game?

Thanks in advance for any help!

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

eswitzer07 avatar image eswitzer07 commented ·

Here is a non-url version of my blueprint

0 Likes 0 ·
eswitzer07 avatar image eswitzer07 commented ·

Doing this for me doesnt return anything. Using the encode json I get the right values, just not formatted properly. The Field name is correct, and TestData does appear correctly when calling "Get Field Names", but when getting the field as string/ as number it returns null and 0.0 respectively. Am I missing something here?

0 Likes 0 ·
starkgaminginc avatar image starkgaminginc commented ·

Would anyone be able to provide a sample blueprint for creating a JSON object array? I am mostly just trying to use the Server UpdatePlayerStatistic node and I haven't wrapped my head around the statistics JSON array and how to add the correct variables to the array. Such as wins/score. If needed we can connect through email: themainstark@gmail.com

0 Likes 0 ·
eswitzer07 avatar image eswitzer07 starkgaminginc commented ·



Here is the function I use to construct the json - it could probably be stream lined a bit, but this works.

Fairly straight forward, I set a variable for the json, and then set fields within it. Then pass that to whatever API call needs it

0 Likes 0 ·
capture.png (132.4 KiB)
starkgaminginc avatar image starkgaminginc eswitzer07 commented ·

Thanks a ton, this is what I needed!

0 Likes 0 ·
1807605288 avatar image
1807605288 answered

I believe this image will give you an idea of what's going on.

To re-iterate in text:
Your blueprint is almost right, but you have to unpack "Data" as a Json Object, before you unpack the "XP" string. You can use "Get Field Names" to determine what fields are contained within your current Json Object.

Also, you generally want to ignore the top white action handle. It executes immediately, which is not useful for an async API call. You can't use the API results from the immediate action handle.


exuserdata.png (148.0 KiB)
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.

eswitzer07 avatar image eswitzer07 commented ·

Doing this for me doesnt return anything. Using the encode json I get the right values, just not formatted properly. The Field name is correct, and TestData does appear correctly when calling "Get Field Names", but when getting the field as string/ as number it returns null and 0.0 respectively. Am I missing something here?

0 Likes 0 ·
Montana Tuska avatar image Montana Tuska eswitzer07 commented ·

Alright I solved the issue. The key here is the returned Json. (This is why I really dislike the Unreal Blueprints. I'd use the blueprints from the Unreal C++ version, they have the data all filtered out into the specific variables).

So, GetUserData returns {"code":200,"status":"OK","data":{"Data":{"TestData":{"Value":"25","LastUpdated":"2018-03-06T01:29:09.256Z","Permission":"Public"}},"DataVersion":1}}

See it? Right now, you GetField("TestData") then try and use AsNumber(or whichever). You can't. It should be like this: GetField("TestData") -> AsObject -> GetField("Value") -> AsNumber.

So doing it like that should solve your issue(I'd post a picture but my blueprint is spaghetti)

1 Like 1 ·
1807605288 avatar image 1807605288 ♦ eswitzer07 commented ·

Off the top of my head, I'm not sure.

Our code is open-source, so you can put breakpoints in our plugin and try to determine exactly what types are inside that json, and why it's not working when you retrieve it as a string. I assume it's giving you defaults for the given types you are trying, because something doesn't match.

I agree that it SHOULD work, but without reproducing your entire example myself, I can't see what's wrong.

@Montana Tuska probably knows more than I do, and can probably see what we are missing.

0 Likes 0 ·
Montana Tuska avatar image Montana Tuska eswitzer07 commented ·

My knee-jerk reaction is to first say I mainly work with the C++ version, so my following response won't be perfect. Judging from the SDK source and your implementation, everything should be right. Obviously it's not working as it should so I'll make a quick dummy project and see if I can help out. The only spot I can think of as having the issue is within that PlayFabJsonObject. I'll pull the example project and see if I can get it working.

0 Likes 0 ·
Andrea avatar image
Andrea answered

the result is always 0.0 when it is 50, has anyone solved it? thank you


immagine.jpg (416.9 KiB)
2.jpg (74.6 KiB)
10 |1200

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

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.