Search Unity

Can't build a project that contains ScriptedImporter

Discussion in 'Editor & General Support' started by Wojtasz, Aug 3, 2019.

  1. Wojtasz

    Wojtasz

    Joined:
    Jun 6, 2018
    Posts:
    1
    Hey guys, I have a problem with Unity and I wasn't able to find any solution.

    I have a project that contains ScriptedImporter for my own file format. It all works in the editor but when I want to build actual exe file I get following errors:

    Code (csharp):
    1. Assets\Plugins\OBLImporter.cs(3,32): error CS0234: The type or namespace name 'AssetImporters' does not exist in the namespace 'UnityEditor.Experimental' (are you missing an assembly reference?)
    2. Assets\Plugins\OBLImporter.cs(7,28): error CS0246: The type or namespace name 'ScriptedImporter' could not be found (are you missing a using directive or an assembly reference?)
    3. Assets\Plugins\OBLImporter.cs(6,2): error CS0246: The type or namespace name 'ScriptedImporterAttribute' could not be found (are you missing a using directive or an assembly reference?)
    4. Assets\Plugins\OBLImporter.cs(6,2): error CS0246: The type or namespace name 'ScriptedImporter' could not be found (are you missing a using directive or an assembly reference?)
    5. Assets\Plugins\OBLImporter.cs(9,40): error CS0246: The type or namespace name 'AssetImportContext' could not be found (are you missing a using directive or an assembly reference?)
    6. Assets\Plugins\OBLImporter.cs(9,26): error CS0115: 'OBLImporter.OnImportAsset(AssetImportContext)': no suitable method found to override
    So how do I solve this problem?
     
  2. Helienio

    Helienio

    Joined:
    Sep 11, 2014
    Posts:
    29
    remove the experimental in unity 2020


    using UnityEditor.AssetImporters;
     
    xevenpublicidad likes this.
  3. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,765
    Problem here looks like you have scripts that are making use of UnityEditor namespace that are not in an 'Editor' folder.
     
    Joe-Censored likes this.
  4. epratt

    epratt

    Joined:
    Oct 15, 2019
    Posts:
    17
    I'm having this problem, too.

    I currently have the scripts listed in my 'Editor' folder in my project assets and when I attempt to build I get the same errors.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.IO;
    4. using UnityEditor.AssetImporters;
    5. using UnityEngine;
    6.  
    7. [ScriptedImporter(1, "pdf")]
    8. public class PDFImporter : ScriptedImporter
    9. {
    10.     public override void OnImportAsset(AssetImportContext ctx)
    11.     {
    12.         byte[] bytes = File.ReadAllBytes(ctx.assetPath);
    13.         PDFAsset pdfa = new PDFAsset(bytes);
    14.  
    15.         ctx.AddObjectToAsset("main", pdfa);
    16.         ctx.SetMainObject(pdfa);
    17.     }
    18. }
    I had some code attempting to grab PDFs in my Resources folder, but it wouldn't work until I added a custom importer for them. Could have changed the extension, but the goal is to reduce the amount of work when adding new PDFs to the build because there are going to be many of them.

    When running the code in Unity it works just fine, but when I go to build it throws these same errors.

    Currently running Unity 2021.1.5f1
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,727
  6. Carocrazy132

    Carocrazy132

    Joined:
    Aug 16, 2015
    Posts:
    15
    Yes, they said that, I'm having the same issue.
    I fixed this by wrapping the whole file in #if UNITY_EDITOR #endif but this definitely seems like a bug.