material object count increase gradually and consume memory

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

7550722--933421--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

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

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

7550722--933397--upload_2021-10-6_19-35-49.png
7550722--933439--upload_2021-10-6_19-52-20.png
7550722--933442--upload_2021-10-6_19-52-44.png

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.

1 Like

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?

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).

1 Like