How to Achieve Same Functionaliy as UJsonBlueprintFunctionLibrary::GetField in C++

Hi,

In the blueprint, there is a JSON utility plugin that we can use to deal with JSON objects. I found that the GetField node will output a wildcard variable. If I store the information of the actor in the JSON object, the GetField can give the actor back to me. How can I achieve this in C++?

Here is what it looks like in the blueprint:


For these two nodes, the SetField will get the actor-specific identifier path and store it in the value field. Then when GetField I can just use this actor and get the property or set the stuff of the actor.

Here is the key value in the JSON:

{"Actor":"/Game/MyEnhancedInputActor.MyEnhancedInputActor_C'/Game/ThirdPerson/Maps/UEDPIE_0_ThirdPersonMap.ThirdPersonMap:PersistentLevel.MyEnhancedInputActor_C_UAID_08BFB8A383C893C201_1726865895'"}

So in C++, how can I call this function? there is a int32& Value. How can I pass value in it?
Here is what I try to do:

This will have an error which is the AActor* cannot convert to int32&.

I do not know if I call this customThunk function in this way, will it work the same as in the blueprint? if not, how can I do this?

Like I have one thought:
I wrap this into a function and if it wants a field with an actor, then I will get the string in the actor, but how can I make it to the actor with this string path?

Thanks for your reply.

No you are not meant to call CustomThunks from C++ code.

As far as I’m aware only the blueprint VM has the capability to fill up the FFrame structure with dynamic FProperties, which are then retrieved via StepCompiledIn in the custom thunk.

C++ generally doesn’t need this. It has templates, and can access underlying systems directly. In this case, function SetField automatically converts object to string reference, and function GetField automatically tries to find the reference via FindObject.

// UObject* Obj
// Convert to string ref
FString Ref = Obj->GetPathName();

// FString Ref
// Try convert to object
UObject* Obj = FindObject<UObject>(nullptr, *Ref);

You can also use LoadObject which can better handle some cases (referencing assets like textures, materials, … and blueprints UClass/TSubclassOf), but I’d recommend sticking to FindObject for object instances.

Thanks for the reply, I think I’ll use this way to store the identifier of Actor

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.