Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

ScriptedImporter throwing exception when using AddComponent

Discussion in 'Experimental Scripting Previews' started by gboulard, Dec 6, 2017.

  1. gboulard

    gboulard

    Joined:
    Nov 28, 2012
    Posts:
    21
    Hello,
    i'm trying to use the experimental ScriptedImporter.

    code with last beta version 2017.3.0f1 (i frist tried with the 2017.2, but same bug occured)
    Code (CSharp):
    1. public override void OnImportAsset(AssetImportContext ctx){
    2.  
    3. var go = new GameObject();
    4. CustomMonoBehaviour comp = go.AddComponent<CustomMonoBehaviour >();
    5. ctx.AddObjectToAsset("MainAsset", go);
    6. //...
    7. }
    when i've got the asset selected in unity , so that the inspector is shown, i got 2 exception :
    and the component is not displayed in the "imported Object" section of the inspector.

    not sure if i missd some step or if it's a bug.
    Any help appreciated
     
  2. gboulard

    gboulard

    Joined:
    Nov 28, 2012
    Posts:
    21
    not a very successful thread :p

    did anyone else have tried the ScriptedImporter ?
    Is it bad practice to AddComponent to created master gameobject ?

    still struggling with this issue.