UFunction with UScriptStruct parameter return corresponding struct

I’m trying to write a blueprint exposed C++ function that takes a UScriptStruct parameter and returns a struct of the corresponding type.

My goal is the write a function that is similar to the Create Actor from Class node. It is my understanding that UScriptStruct is the struct equivalent to UClass. I’ve read how it’s possible to make a function return the same type as a parameter using the metadata specifiers, but I’m trying to return a struct not the same UScriptStruct. Essentially I want to be able to create an instance of the struct corresponding to UScriptStruct and then return it.

Note: I am not taking about the UserDefinedStruct class.

If you have any insight please let me know.

There’s no need to build this yourself. You can enable the StructUtils plugin and use FInstancedStruct. Blueprint support was merged in 5.1.

There is a pending fix which unfortunately did not make it into the hotfix for some reason however:

https://github.com/EpicGames/UnrealEngine/commit/bab6ad5886f2a778957a5d857e4a37b1deff4889

Thank you for the answer.

I took a look at the StructUtils plugin and the FInstancedStruct. I see that there is a SetInstancedStructValue and GetInstancedStructValue, which has a wildcard parameter and return value respectively. This is really close to what I am trying to achieve. Ultimately I am trying to create a function that takes a string and a struct type (or the struct itself) and attempts to initializes the struct with the string and then return the struct.

1 Like