1
\$\begingroup\$

I have an actor class which have a FName UPROPERTY and also an array of strings loaded from config. I need to select a value from that array in editor details of that actor and assign it to that property instead of entering that string manually.

I need the same behaviour as UENUM value selection but for FName.

How to do it?

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

I solved it. The solution is very easy

UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (GetOptions = "GetNameOptions"))
FName Name;

UFUNCTION(CallInEditor)
TArray<FString> GetNameOptions() const
{
    return { TEXT("N1"), TEXT("N2"), TEXT("N3") };
}
\$\endgroup\$
2
\$\begingroup\$

The way I have done this is with a DetailsView widget.

In the object you are editing, add a

UPROPERTY(EditAnywhere)
FNameSelector CustomProperty;

which will be the custom property exposed in the editor details view. Then define FNameSelector and add a custom property for it.

Make a struct to hold the name value:

USTRUCT()
struct FNameSelector
{
    GENERATED_BODY()

    UPROPERTY(EditAnywhere)
    FName Name;

    FAssetCategoryNameSelector()
    {}

    FAssetCategoryNameSelector(const FName& InName) :
        Name(InName)
    {}
};

Make a class with the IPropertyTypeCustomization interface, and put your string data in it somehow,

class FSomeClass: public IPropertyTypeCustomization

In the PropertySelectionChanged callback, set CustomProperty.Name of your object.

In your module, add a custom property type for your object and the selector class that you just made.

Module.RegisterCustomPropertyTypeLayout("NameSelector", FOnGetPropertyTypeCustomizationInstance::CreateStatic(&FSomeClass::MakeInstance));
\$\endgroup\$
2
  • \$\begingroup\$ "In your module" - I don't have a module. It's just a class in my game \$\endgroup\$
    – Robotex
    Mar 21, 2022 at 9:50
  • \$\begingroup\$ Can you give me a code example of IPropertyTypeCustomization \$\endgroup\$
    – Robotex
    Mar 21, 2022 at 10:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .