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 How to implement ScriptedImporter with platform dependency and accelerator friendly?

Discussion in 'Scripting' started by Kichang-Kim, Jun 19, 2021.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    979
    Hi. I tried to implement my own asset importer by using ScriptedImported.

    My asset generates Texture3D so it's format should be changed per each platform (ex, windows-DX5, android-ETC and so on). Also it will process number of textures so its artifacts should be cached.

    How to correctly implement ScriptedImporter for these case?

    I think "AssetImporters.AssetImportContext.DependsOnCustomDependency()" can be used but it should be called before OnImportAsset() because if the asset is cached OnImportAsset() will not be called.

    Thanks.
     
    fum1 likes this.
  2. kurroarashi

    kurroarashi

    Joined:
    Dec 22, 2018
    Posts:
    28
    did you manage to figure out a solution for this?
     
  3. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    979
    No. There is still no documentation.
     
  4. Error-md1

    Error-md1

    Joined:
    Nov 9, 2022
    Posts:
    13
    So this is really terrible, but the way you make a ScriptedImporter produce a platform-dependent artifact is to access AssetImportContext.selectedBuildTarget during OnImportAsset. They do some code in the getter for the property that flags the importer as platform dependent. See https://docs.unity3d.com/ScriptReference/AssetImporters.AssetImportContext-selectedBuildTarget.html. This is perhaps the most confusing and obfuscated way they could've implemented this, and a complete misuse of getters. Thanks, Unity.
     
    Last edited: Apr 27, 2023