Asset user data/properties

Hi there, which is the best way to add a user data to an asset? I just want to be able to select an asset and to add a few key-value properties to it. What is the best practice?

Best,

I managed to add something to Item.TagsAndValues using the emplace method, but it get’s garbage collected outside of the local scope

In case you want to add user data to (for example) static mesh you would need to create subclass of:

UAssetUserData

Then in that derived class define all data members you want and after that you can add this entry and populate it with values. There are various approaches to data driven development so this might not be best solution for you.

If you are looking for more compact storage I would suggest you to look at “Data Asset” or “Data Table”. Right click in Content Browser > Miscellaneous > DataAsset/DataTable.

Thank you!

In the future if someone needs this here is an example that I am using:

UCLASS()
class ARSPEECH_API UMyAssetName : public UAssetUserData
{
	GENERATED_BODY()

public:
	UMyAssetName(const FObjectInitializer& ObjectInitializer) :
		Super(ObjectInitializer)
	{}

	UPROPERTY(Category = "MyCat", EditAnywhere, BlueprintReadWrite)
	FString Name;

	UFUNCTION(BlueprintCallable, Category = "MyCat")
	static UMyAssetName	*GetMyAssetNameUserData(UObject* Object)
	{
		if (AActor* Actor = Cast<AActor>(Object))
		{
			Object = Actor->GetRootComponent();
		}

		if (IInterface_AssetUserData* AssetUserData = Cast<IInterface_AssetUserData>(Object))
		{
			return Cast<UMyAssetName>(AssetUserData->GetAssetUserDataOfClass(UMyAssetName::StaticClass()));
		}

		return nullptr;
	}
};

2 Likes