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 material object count increase gradually and consume memory

Discussion in 'Scripting' started by astrokoo3, Oct 6, 2021.

  1. astrokoo3

    astrokoo3

    Joined:
    Jan 31, 2020
    Posts:
    22
    hi.

    our specific material count named NameTagMaterial increase gradually

    i know if i set or something on renderer.material will clone original material

    but our NameTagMaterial usage so simple and nothing any touch on that material in script code

    upload_2021-10-6_19-44-56.png

    but scaling its transform and child transform

    is it clone the material if i change scale of transfrom?

    i can't find any clue for increasing material count

    upload_2021-10-6_19-52-59.png

    this is the capture that show count and total size, 11326 count and 8.1 megabyte
     

    Attached Files:

  2. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Are you sure there's no script anywhere accessing the renderer.material? Merely reading from it creates a copy of the material that will stay around in memory until you either load a non-additive scene, call Resources.UnloadUnusedResources(), or manually destroy the material yourself.
     
    astrokoo3 likes this.
  3. astrokoo3

    astrokoo3

    Joined:
    Jan 31, 2020
    Posts:
    22
    i'm sure there's no script anywhere accessing the renderer.material.

    but the gameobject of that renderer is per monster object one

    and it will create and destroy frequently at the same time

    so if i create 100 monsters then NameTagMaterial create 100 times also?

    and if the monster destroyed i have to manually destroy the NameTagMaterial?
     
  4. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    The material has "instance" on its name, which indicates it was duplicated. Not sure how that would happen is there are no references to the material property, but seems like the workaround would be destroying the material when you destroy the monster (maybe in the OnDestroy function).
     
    astrokoo3 likes this.