How to do it...

  1. First, we will update the MyCustomAsset class to be editable in Blueprints and reflect what we'll be doing in this recipe. Go to MyCustomAsset.h and update it to the following code:
#pragma once

#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "MyCustomAsset.generated.h"


UCLASS(BlueprintType, EditInlineNew)
class CHAPTER_10_API UMyCustomAsset : public UObject
{
GENERATED_BODY()

public:
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Custom Asset")
FString ColorName;

};
  1. From the Chapter_10Editor folder, create a new file called MyCustomAssetPinFactory.h .
  2. Inside the header, add the following code:
#pragma once
#include "EdGraphUtilities.h"
#include "MyCustomAsset.h"
#include "SGraphPinCustomAsset.h"


struct CHAPTER_10EDITOR_API FMyCustomAssetPinFactory : public FGraphPanelPinFactory
{
public:
virtual TSharedPtr<class SGraphPin> CreatePin(class UEdGraphPin* Pin) const override
{
if (Pin->PinType.PinSubCategoryObject == UMyCustomAsset::StaticClass())
{
return SNew(SGraphPinCustomAsset, Pin);
}
else
{
return nullptr;
}
};
};


  1. Create another header file called SGraphPinCustomAsset.h:
#pragma once
#include "SGraphPin.h"


class CHAPTER_10EDITOR_API SGraphPinCustomAsset : public SGraphPin
{
SLATE_BEGIN_ARGS(SGraphPinCustomAsset) {}
SLATE_END_ARGS()

void Construct(const FArguments& InArgs, UEdGraphPin* InPin);
protected:
virtual FSlateColor GetPinColor() const override { return FSlateColor(FColor::Black); };

virtual TSharedRef<SWidget> GetDefaultValueWidget() override;

void ColorPicked(FLinearColor SelectedColor);
};

  1. Implement SGraphPinCustomAsset by creating the .cpp file:
#include "SGraphPinCustomAsset.h"
#include "Chapter_10Editor.h"
#include "SColorPicker.h"
#include "MyCustomAsset.h"

void SGraphPinCustomAsset::Construct(const FArguments& InArgs, UEdGraphPin* InPin)
{
SGraphPin::Construct(SGraphPin::FArguments(), InPin);
}

TSharedRef<SWidget> SGraphPinCustomAsset::GetDefaultValueWidget()
{
return SNew(SColorPicker)
.OnColorCommitted(this, &SGraphPinCustomAsset::ColorPicked);

}

void SGraphPinCustomAsset::ColorPicked(FLinearColor SelectedColor)
{
UMyCustomAsset* NewValue = NewObject<UMyCustomAsset>();
NewValue->ColorName = SelectedColor.ToFColor(false).ToHex();
GraphPinObj->GetSchema()->TrySetDefaultObject(*GraphPinObj, NewValue);
}
  1. Regenerate your Visual Studio project.
  2. Add #include "MyCustomAssetPinFactory.h" to the Chapter_10Editor.h module implementation file.
  3. Add the following member to the editor module class (FChapter_10EditorModule):
TSharedPtr<FMyCustomAssetPinFactory> PinFactory; 
  1. Open Chapter_10Editor.cpp and then add the following to StartupModule():
PinFactory = MakeShareable(new FMyCustomAssetPinFactory()); 
FEdGraphUtilities::RegisterVisualPinFactory(PinFactory); 
  1. Also add the following code to ShutdownModule():
FEdGraphUtilities::UnregisterVisualPinFactory(PinFactory); PinFactory.Reset(); 
  1. Compile your code and launch the editor.
  2. Create a new Function inside of the Level Blueprint by clicking on the plus symbol beside Functions within the My Blueprint panel:

  1. Add an input parameter:

  1. Set its type to MyCustomAsset (Object Reference):

  1. In the Level Blueprint's Event Graph, place an instance of your new function and verify that the input pin now has a custom visualizer in the form of a color picker:

Newly added color picker visualizer