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 creates locked assets

Discussion in 'Experimental Scripting Previews' started by TinMatt, Jan 14, 2019.

  1. TinMatt

    TinMatt

    Joined:
    Jul 11, 2017
    Posts:
    5
    Hi everyone, I'm just starting looking into ScriptedImporters and have been unable to create assets that are editable in the inspector. Instead the ScriptableObjects I'm making appear like in the screenshot. I'm reading a JSON file with ".deck" suffix and decoding into a deck state.

    My ScriptedImporter code:

    Code (CSharp):
    1. [ScriptedImporter(1, "deck")]
    2.     public class DeckImporter : ScriptedImporter
    3.     {
    4.         public override void OnImportAsset(AssetImportContext ctx)
    5.         {
    6.             var text = File.ReadAllText(ctx.assetPath);
    7.             var scrobj = ScriptableObject.CreateInstance<Data.DeckContainer>();
    8.             scrobj.data = new Data.DeckState(text);
    9.             ctx.AddObjectToAsset("data", scrobj);
    10.             ctx.SetMainObject(scrobj);
    11.         }
    12.     }
    The ScriptableObject class is empty except for the variables that are seen in the inspector, however all the variables are uneditable. I was under the impression that the assets created through the ScriptedImporter were still editable as unity assets. As well as this problem I have a couple more questions about this process:

    - If these assets are editable, is the data serialized onto the created asset? Will the changes be saved in the metadata?
    -The API also mentions that OnImportAsset can export data as well: how can this be done?
     

    Attached Files:

  2. shibasaki

    shibasaki

    Joined:
    Feb 12, 2015
    Posts:
    12
    From inspector, try turning off NotEditable flag in object's hideFlags.
     
    Oneiros90 likes this.