Search Unity

Bug Bug? Textures loaded that were previously used by a material?

Discussion in 'High Definition Render Pipeline' started by dgoyette, Nov 13, 2020.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    I've been looking into some high memory usage in my game, and one thing I've found surprised me. It seems that if a material references a texture, that texture gets loaded, even if the texture isn't used by the current shader.

    For example, I have a standard material I use for a ceiling. It uses the standard HDRP/Lit shader. However, that was not always the case. Previously, this material used a custom shader I had created in Shader Graph. If I look at this material on disk, I can still see the evidence of this in some of its references:

    Code (CSharp):
    1.     - Texture2D_447C3F82:
    2.         m_Texture: {fileID: 2800000, guid: b33b9195e3e0e3941b94fb74bcc5c534, type: 3}
    3.         m_Scale: {x: 1, y: 1}
    4.         m_Offset: {x: 0, y: 0}
    5.     - Texture2D_48FC45F3:
    6.         m_Texture: {fileID: 2800000, guid: 51667394398390b4d94dfd734295474f, type: 3}
    7.         m_Scale: {x: 1, y: 1}
    8.         m_Offset: {x: 0, y: 0}
    9.     - Texture2D_72C0EEC9:
    10.         m_Texture: {fileID: 0}
    11.         m_Scale: {x: 1, y: 1}
    12.         m_Offset: {x: 0, y: 0}
    13.     - Texture2D_965E2220:
    14.         m_Texture: {fileID: 2800000, guid: 5dfe9c270d55e414f9d69c03ea0cec7a, type: 3}
    15.         m_Scale: {x: 1, y: 1}
    16.         m_Offset: {x: 0, y: 0}
    What I'm finding, however, is that even though these old Texture2D_XYZ shader graph references aren't used by the HDRP/Lit shader, they're still getting loaded into video memory:

    upload_2020-11-13_12-42-16.png

    The texture shown there is one of the textures referenced by the unused Texture2D_XYZ references in the material.

    So, as far as I can tell, Unity is just blindly loading these textures, despite them not actually being used by the material. Is that how things work? It also doesn't seem like there's an easy way to purge materials of properties that aren't used by their shaders, so I may be stuck going around cleaning all this up manually. Has anyone else run into this? Is this considered a bug, or a feature?