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
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can we get a ScriptedImporter that does not pack assets inside the build ?

Discussion in 'Experimental Scripting Previews' started by aybeone, Dec 14, 2018.

  1. aybeone

    aybeone

    Joined:
    May 24, 2015
    Posts:
    107
    Basically, I'm working on a modern engine for an old video game, pretty much like what ZDoom is to Doom. All of these engines require the end-user to provide game data from the original game (obviously).

    When I first seen ScriptedImporter, I thought it would magically solve this problem but unfortunately it doesn't, it just ends up generating the asset and adding to the build.

    What I'm currently doing is quite convoluted:
    • use [ExecuteInEditMode] on my behaviour that loads the external asset to have in-editor preview
    • before building the game, ensure to remove any leftovers from the original game in scene, e.g. meshes, textures that are persisted at Unity's discretion
    • it does work ... up to a certain point
    What I'm looking for:
    • a ScriptedImporter that would always load the asset from an external file
    • retain the workflow to have such assets in the Project window, i.e. drag and drop them into a scene
    Been thinking about it and here is how it could be realized:

    Code (CSharp):
    1. // the inheritance is a new type from Unity
    2. class MyCrazyFormatImporterSource : ScriptedImporterSource
    3. {
    4.     // add whatever necessary here
    5.  
    6.     public override string GetAssetPath()
    7.     {
    8.         return path to the asset
    9.     }
    10. }
    11.  
    12. // note the new Resolver property added to the attribute
    13. [ScriptedImporter(1, "whatever", Resolver = typeof(MyCrazyFormatImporterSource)]
    14. class MyCrazyFormatImporter : ScriptedImporter
    15. {
    16.     ...
    17. }
    More or less that, when people wants to use it the usual way, they can, when people would like an asset to be kept as external, they would define the Resolver property.

    Hope that makes sense to the Unity team !

    PS if there's a way to achieve what I'm looking with the existing infrastructure but I missed it, I'm all in.