Dynamically set property metadata

Hi,

This might seem like a dumb question but I’ve been trying to set some metadata dynamically on 2 different attributes of the same type containing a FGameplayTag, but without success.

Given the following example, what would be the best way to achieve this?

`USTRUCT()
struct FInnerStruct
{
GENERATED_BODY()

UPROPERTY( EditAnywhere )
FGameplayTag Tag;

// Other stuff..
};

USTRUCT()
struct FMyStruct
{
GENERATED_BODY()

// I would like Foo::Tag to have meta = (Categories = “TagA”).
UPROPERTY( EditAnywhere )
TArray Foo;

// Though, I would like Bar::Tag to have meta = (Categories = “TagB”).
UPROPERTY( EditAnywhere )
TArray Bar;
};`

I’ve tried the following implementation but it obiviously affects the whole FInnerStruct metadata, and not just the attribute’s metadata.

`bool FMyStruct::Serialize( FArchive& )
{
static const FName NAME_Categories = TEXT( “Categories” );
{
// Attempt to modify FMyStruct::Foo.Tag’s metadata.
FArrayProperty * arrayProperty = FindFieldChecked( StaticStruct(), GET_MEMBER_NAME_CHECKED( FMyStruct, Foo ) );
if ( FStructProperty * inner = CastField( arrayProperty->Inner ) )
{
FProperty * prop = FindFieldChecked( inner->Struct, GET_MEMBER_NAME_CHECKED( FInnerStruct, Tag ) )
prop->SetMetaData( NAME_Categories, TEXT(“TagA”) );
}
}
{
// Attempt to modify FMyStruct::Bar.Tag’s metadata.
FArrayProperty * arrayProperty = FindFieldChecked( StaticStruct(), GET_MEMBER_NAME_CHECKED( FMyStruct, Bar ) );
if ( FStructProperty * inner = CastField( arrayProperty->Inner ) )
{
FProperty * prop = FindFieldChecked( inner->Struct, GET_MEMBER_NAME_CHECKED( FInnerStruct, Tag ) )
prop->SetMetaData( NAME_Categories, TEXT(“TagB”) );
}
}

return false;
}`

Thank you for your help,

- Cédric

Hi Cédric,

Sorry about the delay. Unfortunately, property metadata affects how Unreal’s reflection system handles the property as a type within its container class or struct. This means you won’t be able to set metadata on specific instances of an object.

To achieve what you need, I believe the most straightforward way would be to use a Detail Customization for FMyStruct. You could then create categories as desired and request that the default details of FInnerStruct be shown on each category.

Please let me know if this sounds like an interesting approach, and I’ll be happy to provide an example base implementation for you to build on if you need.

Best regards,

Vitor

Hi,

Sorry about the delay too!

I’m familiar with the Detail Customization but I feel it is quite “much” just to customize 2 gameplay tags filters. I will simply use some data validation to prevent errors.

Thank you for your help :slight_smile: