Search Unity

Bug [Editor] Broken Importer selector

Discussion in 'Editor & General Support' started by Oneiros90, Oct 25, 2022.

  1. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    78
    I'm trying to create a custom importer for package manifest files, which have .json extension.
    This is my code:

    Code (CSharp):
    1. [ScriptedImporter(1, null, new string[] { "json" })]
    2. public class PackageManifestImporter : ScriptedImporter
    3. {
    4.     private static Texture2D manifestIcon;
    5.  
    6.     public override void OnImportAsset(AssetImportContext ctx)
    7.     {
    8.         var manifestJson = File.ReadAllText(ctx.assetPath);
    9.         var manifestAsset = ScriptableObject.CreateInstance<PackageManifestAsset>();
    10.         JsonUtility.FromJsonOverwrite(manifestJson, manifestAsset);
    11.         EditorUtility.SetDirty(this);
    12.  
    13.         if (manifestIcon == null)
    14.             manifestIcon = EditorGUIUtility.IconContent("d_TextScriptImporter Icon").image as Texture2D;
    15.         ctx.AddObjectToAsset(ctx.assetPath, manifestAsset, manifestIcon);
    16.         ctx.SetMainObject(manifestAsset);
    17.     }
    18. }
    My importer is shown in the Inspector in the top selection dropdown but it just doesn't work: when I select a different entry nothing happens, the first one is always selected (this happens by default, even if I don't create the third entry)

    Immagine 2022-10-25 110822.png
     
  2. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    78
    I just tried with different extensions ("txt" and "png") and the same problem occurs: the importer is recognized but it is not selectable
     
  3. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    78
    Ok this was a totally stupid problem.
    I changed the name of the importer and the selector started working. I used the same name as a built-in importer and the editor didn't like that. Please Unity, spawn a warning or something! :(