I am trying to customize the detail view of the UObject with IDetailCustomization
.
Here is the code
UCLASS()
class DETAILVIEW_TEST_API UMyDataAsset : public UDataAsset
{
GENERATED_BODY()
public:
UPROPERTY()
int Num1;
UPROPERTY(meta = (ClampMin = "0", ClampMax = "100"))
int Num2;
};
/**
* Customize the details view for UMyDataAsset
*/
class DETAILVIEW_TEST_API FMyDataAssetDetails : public IDetailCustomization {
public:
void CustomizeDetails(IDetailLayoutBuilder& builder) override {
IDetailCategoryBuilder& Setting = builder.EditCategory("Setting");
// If setup properly, there will be a new row in details view.
Setting.AddCustomRow(FText::FromString("Test"))
.NameContent()
[
SNew(STextBlock)
.Text(FText::FromString("Test"))
.Font(builder.GetDetailFont())
];
// Try to get property and show it
TSharedPtr<IPropertyHandle> Num1_Handle = builder.GetProperty(GET_MEMBER_NAME_CHECKED(UMyDataAsset, Num1));
if (Num1_Handle->IsValidHandle())
Setting.AddProperty(Num1_Handle);
else
UE_LOG(LogTemp, Warning, TEXT("Cannot find property Num1"));
TSharedPtr<IPropertyHandle> Num2_Handle = builder.GetProperty(GET_MEMBER_NAME_CHECKED(UMyDataAsset, Num2));
if (Num2_Handle->IsValidHandle())
Setting.AddProperty(Num2_Handle);
else
UE_LOG(LogTemp, Warning, TEXT("Cannot find property Num2"));
}
static TSharedRef<IDetailCustomization> CreateInstance() {
return MakeShared<FMyDataAssetDetails>();
}
};
I also register FMyDataAssetDetails
, when the module start up.
void MyGameModule::StartupModule()
{
FPropertyEditorModule& M = FModuleManager::Get().LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
M.RegisterCustomClassLayout(UMyDataAsset::StaticClass()->GetFName(),
FOnGetDetailCustomizationInstance::CreateStatic( FMyDataAssetDetails::CreateInstance ));
}
void MyGameModule::ShutdownModule()
{
FPropertyEditorModule& M = FModuleManager::Get().LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
M.UnregisterCustomClassLayout(UMyDataAsset::StaticClass()->GetFName());
}
The result:
This is not what I am expecting. FMyDataAssetDetails ::CustomizeDetails
is called, but I cannot get property handle from IDetailLayoutBuilder
.
Does anyone know how to solve it?