How should I accept wildcard structs for ouput pin in C++?

I’m trying to create a function whose output is wildcard structs.
By referring this tutorial, I made a simple function which output a FStructProperty specified by Target and VarName .

UCLASS()
class SAMPLEPROEJCT_API UWildcardFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	
	UFUNCTION(BlueprintCallable, CustomThunk, meta = (CustomStructureParam = "Result"))
	static void GetStructPropertyValueByName(UObject* Target, FName VarName, bool& Success, UProperty*& Result);

	static void GenericGetStructPropertyValueByName(UObject* Target, FName VarName, bool& Success, UProperty*& Result);

	DECLARE_FUNCTION(execGetStructPropertyValueByName)
	{
		P_GET_OBJECT(UObject, Target);
		P_GET_PROPERTY(FNameProperty, VarName);
		P_GET_PROPERTY_REF(FBoolProperty, Success);
		P_GET_OBJECT_REF(UProperty, Result);

		P_FINISH;
		P_NATIVE_BEGIN;

		UClass* Class = Target->GetClass();
		FStructProperty* Property = FindFProperty<FStructProperty>(Target->GetClass(), VarName);

		Result = Property;
		Success = true;

		P_NATIVE_END;
	}
};

void UWildcardFunctionLibrary::GetStructPropertyValueByName(UObject* Target, FName VarName, bool& Success, UProperty*& Result)
{
    check(0);
}

However, the value of struct variables is not correct.

In the below case, I expect output value is 50.0, but the real one is 0.0.

I’m not sure why this behavior is occurred.
Also, I want to know how to solve this issue.

I think your issue is a more complex task than this

I don’t think it’s possible to do it just by using the custom thunk, unless you know exactly what struct you’re looking for.

I managed to get it to work like so:

	UFUNCTION(BlueprintCallable, CustomThunk, meta = (CustomStructureParam = "Result"))
	static void GetStructPropertyValueByName(UObject* Target, FName VarName, bool& Success, UProperty*& Result);

	static void GenericGetStructPropertyValueByName(UObject* Target, FName VarName, bool& Success, UProperty*& Result);

	DECLARE_FUNCTION(execGetStructPropertyValueByName)
	{
		P_GET_OBJECT(UObject, Target);
		P_GET_PROPERTY(FNameProperty, VarName);
		P_GET_PROPERTY_REF(FBoolProperty, Success);

		Stack.StepCompiledIn<FStructProperty>(NULL);
		void* Result = Stack.MostRecentPropertyAddress;
		P_FINISH;
		
		FStructProperty* Property = FindFProperty<FStructProperty>(Target->GetClass(), VarName);
		if (Property)
		{
			void* StructProperty = Property->ContainerPtrToValuePtr<void>(Target);

			if (StructProperty)
			{
				P_NATIVE_BEGIN;
				Property->Struct->CopyScriptStruct(Result, StructProperty);
				Success = true;
				P_NATIVE_END;
			}
		}
	}

However, this will not change the pin type on the node, which means that you will need to know what struct it is, and connect the result pin to a node that accepts a struct of that type, otherwise it will not compile, and will probably crash if you connect it to a struct of another type.

You would have to create a custom node in order to automatically determine the type of the result struct pin, which is a bit more complicated. If you want to do it, you should take a look into UK2Node_GetDataTableRow, which does something similar to what you want to do, although your node will only require a small part of that. But the important part would be to override PinDefaultValueChanged and change the type of the result pin to that of the struct property (if found). The nice thing about this is that it will also provide compile time errors if the property is not found.

Thanks, it works perfectly.

As you mentioned, making a custom node is needed to realize the automatic pin change.
I has already tackling this, but your information is very helpful.
Thanks so much for your information.