Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Prevent the loading of textures

Discussion in 'General Graphics' started by OmegaNemesis28, Jul 3, 2019.

  1. OmegaNemesis28

    OmegaNemesis28

    Joined:
    Dec 1, 2012
    Posts:
    15
    • I have a whole scene in unity with lots of game objects. Many of these game objects have meshrenders with a material applied. They have 2D textures in albedo for example.
    • I also have a bunch of 2D lightmaps.
    • I also have cubemaps loaded.
    I do not want these loaded in my scene under certain conditions. Let's say I want to play the game completely without textures for profiling memory. The ultimate goal I have is to prevent the textures from ever eating up memory.

    Is there anything in Unity that's built in that would allow me to do this? Or do I need to script something on Scene load to traverse every gameobject to prevent the meshrenders from loading those textures somehow? I do not want to have to go to every single prefab and gameobject and by hand have to create specialized presets, there's far too many to do manually in any efficient way and would be a burden on my artists for any new asset creation.
     
  2. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    151
    As I know, you can use AssetBundles, which is loaded to memory when you write-specific-code, and unloaded completely from memory when you want. It work on any platform (PC, webgl, mobile).

    To assign specific prefabs to concrete AssetBundle, you can use C# editor script, which can automatically do it, with specific logic, with known input-format of PNG and any-other (if need, JSON config for example).

    Example of workflow: you place A1_Albedo.png and A1_Lightmap.png in specific folder (or your artist), when unity invoke your asset-import-script and creates prefab with assigned A1_Albedo.png as Albedo in your asset, etc, then creates AssetBundle and assign this gameObject and prefab - to AB. After all - it can build AB to specific file.

    All of those asset-importing and post-processing logic can be written, concrete examples and manuals you can search yourself (cant provide links and examples of code)
    this one I have found https://docs.unity3d.com/ScriptReference/AssetPostprocessor.html