Search Unity

User-defined prefab generation using ScriptedImporter with referenced assets, possible?

Discussion in 'Prefabs' started by Kichang-Kim, Aug 7, 2019.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Hi. I'm trying to implement custom importer for generating prefab by using user-defined custom data.

    In example, user-defined data has multiple name and guid pair, and ScriptedImporter generates prefab which has multiple childs with PlayableDirector and specific timeline, loaded via guid.

    I think this works when all of assets are already imported. But how about first time mport of project? when custom data is imported, other assets which has guid in pair may not be imported so AssetDatabase.LoadAsset by guid may be failed.

    My other concern is that when I generate prefab in ScriptedImporter, its guid may be changed and all references to prefab may be lost.

    So, my question is,
    1. Is this possible to create asset which references to other asset in ScriptedImporter?
    2. How to safely create/update prefab in ScriptedImporter for preserving its guid?

    Thanks.
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    I'm guessing that giving the importer a high importQueuePriority would guarantee that it runs later than the other assets.
     
  3. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @Kichang-Kim

    1) Yes is it possible to reference other assets from a ScriptedImporter.

    2) As long as the names of the GameObjects you create are stable you will also get stable ids and thus references to your custom prefab should be fine.
     
    Kichang-Kim likes this.
  4. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Oh, That is exactly what I found. Thanks.