Search Unity

Nested prefabs in ScriptedImporter

Discussion in 'Prefabs' started by palex-nx, Jul 24, 2018.

  1. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Hello community!

    I've succeeded creating the nested prefab via script, but when adding it to the AssetImporterContext as a main object nesting gets broken. When I drag the imported object to the scene I see regular gameobject inside, not a nested prefab. Is it possible to add the prefab with nesting to the custom imported assset?

    Thank you!
     
    Last edited: Jul 24, 2018
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    I'm told this is not supported. Unfortunately the dev who is knowledgeable about this specific issue is on vacation. I can't provide more details for now.
     
  3. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Hi runevision! Thank you for clarification. I'll create my prefabs in the project folder next to the imported asset then. Hope designers will be happy with that.
     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Hello there! I've got a response from support saying this is not supported by design. When the assset database is in importing state a prefab can not be created.
    Now I have a question. How do I import some binary or text file as prefab? Basically my file contains objects definitions and instances hierarchy description. Nested prefabs is perfect representation for this structure.
    I'd like to put my file in Assets folder, apply some ScriptedImporter magic to it, and get a bunch of prefabs with some nesting created according to the file content. If creating prefabs during asset import is not supported, then how should I accomplish this task? May be I could read the file, save it's data temporarily and then create my prefabs in asset postprocessor or what? Thank you!
     
  5. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Hi,

    I am not sure I fully understand what you are trying to do.
    If you want a ScriptedImporter to create additional assets this is not allowed.

    If you want a ScriptedImporter to simply generate imported prefabs, the small example here does exactly that https://docs.unity3d.com/ScriptReference/Experimental.AssetImporters.ScriptedImporter.html

    The trick is simply to create GameObjects. If you create a hierarchy yon only need add the root GameObject as far as I remember. If you add multiple GameObject you will get multiple prefabs inside a single imported file but it is not allowed to have the GameObject belong to the same hierarchy.

    I don't think the ScriptedImporter currently support that you instantiate Prefabs in order to do nesting.
    I know for a fact that prefabs generated from a ScriptedImporter can't be nested inside other prefabs nor can you create variants. This is something we will investigate to fix.

    Cheers
    Steen
     
  6. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Hello!, Sorry for late responce, but the problem remains actual. Resource I'm trying to import is animation from another program for animations not supported in unity. It contains descriptions of objects (sprites, etc) and a hierarchy. Those objects are threated as building blocks for the hierarchy. In the hierarchy the instances of the objects described can appear multiple times on differenet positions, scaled, rotated, etc. I just want to create prefabs according to the description and then instantiate and nest them according to the hierarchy. This would be ideat solution for my case.