How to create a C++ struct that behaves similarly in Blueprint to Vector with inlined textboxes like "X:[0.0] Y[0.0] Z[0.0]"?

Here is an example:

USTRUCT(BlueprintType)
struct FMyVector
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	double X;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	double Y;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	double Z;
};
...

	UFUNCTION(BlueprintCallable)
	static void NativeVectorFunc(FVector SomeVector) {}

	UFUNCTION(BlueprintCallable)
	static void MyVectorFunc(FMyVector SomeVector) {}

This ends up looking like:

blueprint

How can I make my type display similarly to Vector?

I have some types with a large number of similarly grouped values, and it creates quite messy Blueprint nodes, even when hiding the advanced options. Being able to emulate this functionality would help clean things up, alot.

Unfortunately only specific known types are forwarded to specific graph pin widgets classes, it’s all hardcoded FNodeFactory::CreateK2PinWidget :

Other types fallback to a default uncustomized basic pin (of class SGraphPin).
Afaik there is no way to provide customization.

Heyo I was wrong.
I missed a block of code that allows users to inject custom factories for graph pins :

You can register new factories like this (preferably during engine/editor initialization) :

FEdGraphUtilities::RegisterVisualPinFactory(MakeShared<FTestPinFactory>());

I just made a snippet with a full working example, with a struct containing a string and an integer, and made the two fields editable directly within the node.
Sample struct :

USTRUCT(BlueprintType)
struct FSomeStruct
{
    GENERATED_BODY()
    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    FString Str;
    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    int32 Int;
};

Sample function

UFUNCTION(BlueprintPure)
static FSomeStruct SelectSomeStruct(FSomeStruct A, FSomeStruct B, bool bPickA)
{
    return bPickA ? A : B;
}

Result

Full snippet

2 Likes

Much appreciated! That is exceptionally useful, and seemingly not at all documented!

Do you happen to know how to have these custom pins properly display defaults? I’ve tried seemingly everything here to no avail.

There’s some weird behavior where it will only properly display whatever defaults you set in the default constructor, after the blueprint itself is saved. It makes for quite a poor UX when suddenly the values just change after the use first saves.

Oddly enough, everything works perfectly after that first save - when the defaults are loaded in. So it’s not like they’re just simply overwriting what the user inputs.

This seems to work for me, can you try it

image

Great! Oddly enough that exact solution didn’t work (5.2, Windows) but tweaking it just slightly did!

void SGraphPinSomeStruct::Construct(const FArguments& InArgs, UEdGraphPin* InGraphPinObj)
{
	SGraphPin::Construct(SGraphPin::FArguments(), InGraphPinObj);
	
	FSomeStruct DefaultValue;
	DefaultValue.Str = "abcd";
	DefaultValue.Int = 12;

	if(GraphPinObj->DoesDefaultValueMatchAutogenerated())
	{
		GraphPinObj->GetSchema()->TrySetDefaultValue(*GraphPinObj, LexToString(DefaultValue));
	}
}

Thanks again for the help! Learning this system has been a process, but quite fun in its own masochistic way.

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