Custom asset showing up twice in menu

Hi

I’m trying to create a custom asset type and make it show in menu.

In module, I register the new asset type and category like this:

IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();

// Creating custom category
EAssetTypeCategories::Type gameAssetCategory = AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("JsonEditor")), LOCTEXT("JsonEditorCategory", "JsonEditor"));

// registering custom asset action
AssetTools.RegisterAssetTypeActions(MakeShareable(new FATA_UJsonDataAsset(gameAssetCategory)));

And in asset action, I’m returning the asset category in GetCategory() function

In the editor menu I see the asset twice

306269-capture-2.png

If i remove this line in module

// Creating custom category
    EAssetTypeCategories::Type gameAssetCategory = AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("JsonEditor")), LOCTEXT("JsonEditorCategory", "JsonEditor"));

and not register the category, asset isn’t showing up at all. (Assuming that is intended behavior)

Why is the asset showing twice in menu.

Thanks

Are you Unregistering while unloading the Module? It is possible the module is loaded, unloaded and loaded again when the engine is launching

I wasn’t before but I updated the code to this

StartupModule:

IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();

EAssetTypeCategories::Type gameAssetCategory = 

AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("JsonEditor")), LOCTEXT("JsonEditorCategory", "JsonEditor"));

TSharedPtr<IAssetTypeActions> actionType = MakeShareable(new FATA_UJsonDataAsset(gameAssetCategory));

AssetTools.RegisterAssetTypeActions(actionType.ToSharedRef());

CreatedAssetTypeActions.Add(actionType);

ShutdownModule:

if (FModuleManager::Get().IsModuleLoaded("AssetTools"))
	{
		// Unregister our custom created assets from the AssetTools
		IAssetTools& AssetTools = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools").Get();
		for (int32 i = 0; i < CreatedAssetTypeActions.Num(); ++i)
		{
			AssetTools.UnregisterAssetTypeActions(CreatedAssetTypeActions[i].ToSharedRef());
		}
	}

CreatedAssetTypeActions.Empty();

I checked the IAssetTools file to see if there is any function to unregister the asset category but there is none.

It didn’t work though, it is still showing up twice.

I really appreciate this great post that you have provided us. I guarantee this will benefit most people and myself. thank you very much!
fnaf

I have created a small project using similar code you have provided [GithubLink][1]. It works as intended, so we can assume the error is elsewhere in your code. Please go trough the plugin code and try to spot what you have done differently in other classes.

Hope this helps!

Oh hey thanks to your comment I realised that factories are the ones responsible for creating these menus and that I had two factories (one for creating and one for importing) and forgot to set the

bCreateNew = false; // turned off for import
bEditorImport = true; in import factory

That is why import factory is also showing up in the menu

Thanks for the help :slight_smile: