Hey everyone, I have a scripted importer which imports a file differently I’d like to add a few helper functions to configure it easier. Usually I do this by writing a static function and decorating it with something like this:
[MenuItem("CONTEXT/TextureImporter/ConvertAndRemap", false, 15)]
That works perfectly, now I try to do the same for a scriptedimporter that is defined as an override importer. But here the menu item does not show up. What am I doing wrong?
[ScriptedImporter(1, null, new[] { "png" }, 2)]
public sealed class ProjectedTextureImporter : ScriptedImporter
{
...
[MenuItem("CONTEXT/ProjectedTextureImporter/Test", false, 15)]
public static void FindMeshAndSecondaryTexturesMenuCommand(MenuCommand menuCommand)
{
ProjectedTextureImporter importer = (ProjectedTextureImporter) menuCommand.context;
FindMeshAndSecondaryTextures(importer.assetPath, ref importer.meshes, ref importer.secondaryTextures);
EditorUtility.SetDirty(importer);
}
}
That’s your issue: “CONTEXT/ …”
There is no ‘context’ for an importer.
Also, I don’t think your importer will work to begin with since you are trying to add an importer for which there already exists a built-in importer. Not even with AssetDatabase.SetImporterOverride. You can try but as far as I recall this won’t work.
You can only do the odd thing and make an importer for “mypng” and save images that need to go through your importer with your custom extension.
@CodeSmile thanks for your reply, but I am afraid you might be wrong on both points?
I can 100% assure you the scripted importer works and that regular importers do have a context menu hook that can be targeted with “CONTEXT/”
I admit the importer context menu is poorly placed right below the window context menu but it definitely exists.
Oh I see, that’s where the context menu is supposed to be. I only did a quick check adding this context menu to an importer but only checked the right-click project/scene view context menu.
But I could swear you can’t override a built-in importer. I wanted to do this at one time for a text format that Unity “supports” (either csv or txt) where I learned the hard way this wouldn’t work. Might have changed over time perhaps? I think I tried it in 2021.
That seems very likely ^^
I found a few posts and documentation page for unity 2018 which state that built in importers can not be overriden, but at least sind AssetDatabase.SetImporterOverride() landed I think it works.
Nonetheless why doesn’t CONTEXT/ not work for scripted importers xD?
I thought this was implemented so much higher up in the chain of things that it should work.