Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question What is the proper usage of AssetImportContext.LogImportError

Discussion in 'Scripting' started by eliashodel, Jan 13, 2022.

  1. eliashodel

    eliashodel

    Joined:
    Jan 25, 2019
    Posts:
    18
    Hi There!

    I have written a ScriptedImporter for a custom file that i use. Everything works fine, however i don't understand how i'm supposed to use
    AssetImportContext.LogImportError(string message, Object obj)


    What should happen when i pass the obj? I expcted that the User can click the ErrorMessage in the console and directly jumps to the Asset that threw the Error? But i don't see any difference in functionality or anything no matter if i pass the Object or not...

    Am I missunderstanding the Methode, or am i passing the wrong Object?

    my code:

    Code (CSharp):
    1.  public override void OnImportAsset(AssetImportContext ctx)
    2.         {
    3.            // some validation stuff
    4.  
    5.             if (manifestFound)
    6.             {
    7.                 ctx.AddObjectToAsset("PackageManifestArchive", archive);
    8.                 ctx.SetMainObject(archive);
    9.             }
    10.             else
    11.             {
    12.                 ctx.LogImportError("Manifest Archive does not contain manifest.json", AssetDatabase.LoadAssetAtPath<DefaultAsset>(ctx.assetPath));
    13.             }
    14.         }
    Thanks for your insight!
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Try passing ctx.mainObject instead of loading an object?
     
  3. eliashodel

    eliashodel

    Joined:
    Jan 25, 2019
    Posts:
    18
    good idea, but unfortunately no luck...

    there still is no difference between calling LogImportError with or without an Object...
    But should there be any difference? the difference is pretty sparse

    btw, i'm using 2020.3.0f