Search Unity

Question How is the long size calculated from Profiler.GetRuntimeMemorySizeLong

Discussion in 'Scripting' started by AurelienChab, Mar 30, 2023.

  1. AurelienChab

    AurelienChab

    Joined:
    Dec 1, 2022
    Posts:
    1
    Hello,

    I am building a tool to verify my materials and textures. In my script I am using the method
    UnityEngine.Profiling.Profiler.GetRuntimeMemorySizeLong to get the size of all the textures used by the selected material.
    This method returns exactly 2x the size displayed in the editor when you preview your texture.

    How is this size calculated, what does it represent exactly ?
    If I want to get the texture memory usage, do I have to divide the result by 2 manually or is this returned size accurate ?
     
  2. GrahamHuws

    GrahamHuws

    Unity Technologies

    Joined:
    Mar 14, 2022
    Posts:
    20
    Hi @AurelienChab! GetRuntimeMemorySizeLong will include the impact on the CPU side and GPU side, so may appear to be double what you might expect.
    In Editor, both CPU and GPU copies are always loaded, but in players, marking the texture as Read-Only should mean you only have the GPU copy.
     
    MartinTilo and Bunny83 like this.