Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Custom material importer

Discussion in 'Scripting' started by crowmaster, Apr 14, 2021.

  1. crowmaster

    crowmaster

    Joined:
    Jul 6, 2012
    Posts:
    73
    I am using ScriptedImporter for importing materials from custom format into unity, it works but resulting material properties are not editable. Any way to fix that?
     
  2. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,049
    That's intended and also how e.g. prefabs and materials created by the model importer work. When the importer runs again, it would have to overwrite or merge your changes, so instead Unity opted to make the imported objects read-only.

    The idea is that you edit your custom material format instead of editing the imported result. If you do want to edit the generated material in Unity, you maybe want to create something other than a ScriptedImporter or add an option to extract the material and create a separate material asset, like the model importer is doing.
     
    crowmaster and karl_jones like this.
  3. crowmaster

    crowmaster

    Joined:
    Jul 6, 2012
    Posts:
    73
    Thanks for answer.
    My problem is that source material is not 1-to-1 into unity material, but is only a small subset of it, and rest of properties are to be tuned manually.

    Anything specific?
     
  4. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,049
    You could make your source material more like templates, adding editor commands or some kind of UI to easily create new material assets based on it.

    Or use AssetPostprocessor.OnPostprocessAllAssets to know when the source asset was changed, create an editable material as a sub-asset and then handle merging user and source changes yourself.
     
    crowmaster likes this.
  5. crowmaster

    crowmaster

    Joined:
    Jul 6, 2012
    Posts:
    73
    Okay, thanks.