Unreal – Make&Break function of custom USTRUCT structure

Suppose we have a structure with the USTRUCT macro, and we want to be able to make or break in our own way in the blueprint. This requirement is usually because we use members in the structure that do not support reflection in C++.

USTRUCT(BlueprintType, Meta = (HasNativeMake, HasNativeBreak))
struct FMeshVertex
{
    GENERATED_BODY()

    UPROPERTY(EditAnywhere)
    FVector Position;

    UPROPERTY(EditAnywhere)
    FVector TangentX;

    UPROPERTY(EditAnywhere)
    FVector TangentY;

    UPROPERTY(EditAnywhere)
    FVector TangentZ;

    UPROPERTY(EditAnywhere)
    FVector2D UVs[8];

    UPROPERTY(EditAnywhere)
    FColor Color;
};

For example, in the above structure, the UVs member is a native fixed-length C array. At this time, the traditional Make&Break cannot access this member, and we need to use the native custom Make&Break function.

USTRUCT(BlueprintType, Meta = (HasNativeMake, HasNativeBreak))

By adding the HasNativeMake&HasNativeBreak tag to the Meta metadata of the USTRUCT macro, we can let the reflection system know that we want to use the custom Make&Break function instead of the system-generated function, so that we can customize the Make&Break function in UBlueprintFunctionLibrary.

UCLASS(Meta = (BlueprintThreadSafe))
class UMeshVertexBlueprintLibrary : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

public:

    UFUNCTION(BlueprintPure, Meta = (NativeMakeFunc, AutoCreateRefTerm = "Position, TangentX, TangentY, TangentZ, UV0,  UV1, UV2, UV3, UV4, UV5, UV6, UV7, Color", AdvancedDisplay = "TangentX, TangentY, UV1, UV2, UV3, UV4, UV5, UV6, UV7"))
    static FMeshVertex MakeMeshVertex(const FVector& Position, const FVector& TangentX, const FVector& TangentY, const FVector& TangentZ, const FVector2D& UV0, const FVector2D& UV1, const FVector2D& UV2, const FVector2D& UV3, const FVector2D& UV4, const FVector2D& UV5, const FVector2D& UV6, const FVector2D& UV7, const FLinearColor& Color);

    UFUNCTION(BlueprintPure, Meta = (NativeBreakFunc, AdvancedDisplay = "TangentX, TangentY, UV1, UV2, UV3, UV4, UV5, UV6, UV7"))
    static void BreakMeshVertex(const FMeshVertex& InVertex, FVector& Position, FVector& TangentX, FVector& TangentY, FVector& TangentZ, FVector2D& UV0, FVector2D& UV1, FVector2D& UV2, FVector2D& UV3, FVector2D& UV4, FVector2D& UV5, FVector2D& UV6, FVector2D& UV7, FLinearColor& Color);

};

Customized Make&Break functions need to be marked with NativeMakeFunc&NativeBreakFunc metadata. This can change the appearance of the function in the blueprint so that it has the same node appearance as the default Make&Break.


  • BlueprintType – Indicates that a structural blueprint is available
  • HasNativeMake – The structure has a native custom Make function
  • HasNativeBreak – The structure has a native custom Break function
  • NativeMakeFunc – Marks the function as a native custom Make function of a structure
  • NativeBreakFunc – Mark function is a native custom Break function of a structure
  • BlueprintThreadSafe – Thread-safe and can be used in multi-threaded blueprints such as animation blueprints
  • BlueprintPure – A function is a pure blueprint with no execution flow pins and represents an uncertain number of executions and timing.
  • AutoCreateRefTerm - This parameter can be defaulted in the automatic creation reference blueprint. The const& parameter will behave like a parameter passed by value.
  • AdvancedDisplay – Marked as advanced parameters, the default folding requires clicking the small triangle below the node to expand it.

Post Reply