Nativize Blueprint assets with CustomThunk

Hi.

I am trying to build with the nativizeAssets flag that are going to go out of beta with the 4.15 release but I am having trouble with one of our custom blueprint nodes.

What we are doing are creating a JsonToStruct (and StructToJson) node that has a signature that looks like this:

UFUNCTION(BlueprintCallable, Category = "Valhalla|Server", CustomThunk, meta = (CustomStructureParam = "structToFill"))
static void JsonToStruct(const UProperty* structToFill, const FString& json);

As we need to use the wildcard struct we use the CustomThunk with DECLARE_FUNCTION(execJsonToStruct){ … }
See this gist for complete implementation.

The build crashes with the error: ‘JsonToStruct’: is not a member of ‘FCustomThunkTemplates’

Complete build log can be found here.

I would love to get some advice on how to troubleshoot this as I have played around with this several days now but not finding a solution.

Hello PhroZenOne,

I’m currently looking into this for you. I’m not familiar with this specifier as of yet so I’ll need to look into that but just from comparing your setup to some in the engine such as the declaration for GetStructFromBox in StructBoxLibrary.h in the engine, I can see that the UFunction declaration and the DECLARE_FUNCTION parts are in the .h for the class while your gist is listed as being in the .cpp. Could this be related to the problem as it seems like a possible parsing/include issue?

I also see that this example one uses the following line for its variables that are being passed in by reference, although I’m not sure that omitting that would cause this behavior.

PARAM_PASSED_BY_REF(StructBox, UStructProperty, FStructBox);

The declaration and everything is in the header file, error from my side to write .cpp in the gist. Sorry about that!

Also I should mention that in the .cpp is only a no-op like GetStructFromBox,

void UVHServerCommunication::JsonToStruct(const UProperty* structToFill, const FString& json) {
	check(0);
}

The StructBoxLibrary is only in beta so maybe that is something that does not compile as well? I will try to set that up and see if StructBoxLibrary does work with nativizeAssets.

I’ve made a minimal project where you can try this out:

https://valhalla-game.com/stuff/nativizeAssets.rar

It implements the jsonToStruct function and uses it in the first person characters begin play blueprint.

Ah, I didn’t realize that StructBoxLibrary was also in beta; How about the functions in KismetArrayLibrary then? I notice that the CustomThunk functions there also include a P_NATIVE_BEGIN; and P_NATIVE_END; surrounding the function’s logic.

So, I have tried playing around with StructBoxLibrary but I cannot get that to work with nativizeBlueprint (now testing with 4.15.0) so it seems that plugin is broken as well.

I have also tried messing around with the P_NATIVE_BEGIN; and P_NATIVE_END; but it does not help. I still get it to run as it should, but not nativize properly I’m afraid.

Edit: What seems to happen is that nativization replaces the custom thunk with the code declared in the FCustomThunkTemplates struct. But that struct is defined in the engine so we, that do not want to make changes to the engine, can never create custom thunks and run nativization.

Can I get a confirmation on my theory and if that is the case, would it be possible to redesign to allow for customization (as I was thinking of building a plugin for http communication and it would be an annoying for everyone using the plugin to have to disable nativization for this files)?

Hi PhroZenOne

What seems to happen is that nativization replaces the custom thunk with the code declared in the FCustomThunkTemplates struct.

That’s right.
FCustomThunkTemplates is not intendet to be used outside the engine, so we don’t support it in nativization (yet).
The GeneratedCodeHelpers.h file is included only in nativized code, so you can modify it (without risk of breaking the actual engine code). As a workaround you can add FCustomThunkTemplates::JsonToStruct funtion (and include a proper header).

If the plugin/module containing the header is not automatically included by NativeAssets module, then add “+AdditionalPublicDependencyModuleNames=” in [BlueprintNativizationSettings] in your DefaultEditor.ini.

Any update to supporting this in engine without modifying source?

How is that exactly possible to extend the FCustomThunkTemplates with an additional function? C++ doesn’t support declaring additional methods after the existing class declaration.