EverNewJoy / VictoryPlugin

Rama's Victory BP Plugin
MIT License
867 stars 256 forks source link

JSON Blueprint Functions #70

Closed Downchuck closed 4 years ago

Downchuck commented 4 years ago

These add JSON serialization and deserialization of objects and structs; though the intention is toward helping with structs.

Deserializaation expects an input struct or object which it will then populate; thus users should use "Make" and manage their object pool appropriately when working with a large amount of data.

This uses built-in JSON serialization and deserialization methods from Unreal and works around some of the higher level API issues that exist (key names are normalized, instead of using author names; deserialization does not work as expected).

LICENSE.md is included as explicit MIT license.

EverNewJoy commented 4 years ago

Thank you so much for this @Downchuck

This is great!!!

You're awesome!

If you can tell me your UE4 forum name I can PM you a Victory Contributor badge!

Rama

EverNewJoy commented 4 years ago

Some Compile Warnings

Would you mind addressing these compile warnings?

image

image

image

There are also some compile errors here:

image

image

You can test using the same build path I am using with this batch file:

@echo ~~~ Dont run this in your project dir, IT DELETES EVERYTHING IN ITS PATH ~~~ 
@echo ~~~ Also make sure you are using the correct Engine version for RunUAT for your project ~~~
@echo ~~~ Enjoy! -Rama ~~~ 

"E:\UE4Engine\UE_4.25\Engine\Build\BatchFiles\RunUAT.bat" BuildPlugin -Plugin="E:\Unreal Projects\Sun\Git\VictoryPlugin\VictoryBPLibrary.uplugin" -Package="%CD%\Output25" -Rocket

Replacing the paths as necessary, please make sure to use a NEW folder for your output, all prior folder contents get erased!

Rama

Downchuck commented 4 years ago

Will do! Big thanks for the quick response.

Code (and my brain) got a bit mangled as I am unfortunately working with four different versions/installs of Unreal. Ooffft!

Downchuck commented 4 years ago

@EverNewJoy

I am hitting an issue in 4.25: inline make structure is not reading the updated value for the From Json method. Using a variable and passing it in works as expected.

This was working fine in 4.22. Trying to dig in and see what on earth is going wrong, as the code is pretty simple:

void* StructPtr = Stack.MostRecentPropertyAddress;

The structure at the pointer is updating correctly, I can serialize and print it to a log:

UE_LOG(LogTemp, Warning, TEXT("JSON: %s"), *TJsonString);

It seems like it could be related to the switch from: UProperty* to TFieldPath -- it really seems like it's making a copy of the structure.

Downchuck commented 4 years ago

As it turns out, Make Structure is making a new structure on each call -- so a Set Members (or Set Variable) node is appropriate following make structure to get a reference. Submitting the PR shortly.

EverNewJoy commented 4 years ago

Okay I am looking forward to it, thank you for the message!

Rama

Downchuck commented 4 years ago

@EverNewJoy - Right now the pins are only input pins, for efficiency this ensures we aren't creating a new struct. Great for variables, and "Set Members" also passes by reference. But it's easy to make a mistake with Make Structure, because there is no output node.

I'm going to spend a little time researching to see if I can setup an output node which works, preserving type and reference to the input FProperty. The StepCompiledIn method is a bit difficult to find documentation for; it seems like the Kismet Library for Arrays shows an example of populating an output reference, using StepCompiledIn(obj) to an allocated and instantiated integer. Mostly I just crashed unreal, and got to some weird "Return Value" can not blah blah blah errors.

On a separate note, this MIT licensed project exposes the Json object itself, which has its own usefulness and complements the Property to Json/Json to Property, for complicated situations in which a message may be of several formats (composed or union): https://github.com/Cl1608Ho/JsonBlueprint

Does that project look compatible with Victory for pulling it in?