C++ Asset Action Utility Not Appearing in Editor Context Menu

Hello,

I am having some issues with the UAssetActionUtility class. Creating a subclass in editor has no issues and everything works as expected. However I am trying to create a subclass purely within C++ and am clearly missing something as the function name does not show up in the context menu for the asset.

.h file

UCLASS()
class UMyAssetAction : public UAssetActionUtility
{
GENERATED_BODY()

public:
UMyAssetAction();

UFUNCTION(CallInEditor)
void Generate();

};

.cpp


UMyAssetAction::UMyAssetAction ()
{
	SupportedClasses.Add(UMyAsset::StaticClass());
	SupportedClasses.Add(UMyOtherAsset::StaticClass());
}

void UMyAssetAction::Generate()
{
	TArray<UObject*> myAssets = UEditorUtilityLibrary::GetSelectedAssets();

	for (UObject* myAsset : myAssets )
	{
		if (myAsset->IsA(UMyAsset::StaticClass()))
		{
		}
       else if (myAsset->IsA(UMyOtherAsset::StaticClass()))
		{
		}
	}
}

The “Generate” function won’t appear in editor however if I just create an empty BP inheriting from UMyAssetAction then Generate immediately starts working.

I assume I need to register something in the Editor Module but I am just not sure what.

Override the GetSupportedClass function and return the class of your asset in it.

If your asset is a blueprint then you need to use UBlueprint::StaticClass(), but in this case, you will see your function on all blueprints, since the ASSET type is a blueprint.

You cannot specify an asset class that is edited via blueprint as the type.

GetSupportedClass isn’t virtual and was also deprecated in 5.2. The expected workflow is to fill out the SupportedClasses array which I do.

I believe the issue lies with your function declaration. It should look like this:

UFUNCTION(meta = (CallInEditor = true))
void Generate();

That is, the CallInEditor should be in the meta.

Edit: Yours is correct. DON’T use the meta.

I missed that last part where you said you needed to create an empty Blueprint inheriting from your class. I believe that is what you’re supposed to do.

Wow, Epic added an array of classes? I’m just doing a project on 5.1 and don’t often follow innovations…

Can you create UMyAsset and UMyOtherAsset from right click in content browser?

The Asset Action Utility can only work with this asset types (or am I missing something?).
You need to register your asset type, as in this article.

Yeah it just seems so weird and wasteful when my code is doing all the work and I basically have to make an empty shell blueprint just so that work can be executed.

1 Like

Yeah the assets do exist in the editor so I can right click them and perform asset actions on them. The problem is that my asset action utility class which I wrote in C++ doesn’t have its functions show up in the context menu unless I create a blueprint child of my asset action utility first.

It just seems so weird that I can’t register my utility class somewhere in code to have it appear in the asset context menu whilst just making an empty blueprint that inherits from it immediately works.

1 Like