You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the main game is loaded (world.zen; without NPCs), we have over 1.2k Materials initialized. When looked at our mesh creation logic, we always create new Material(...) when creating a mesh or calling Renderer.mesh.Set*() when altering data which creates a clone of the Material.
TODOs:
Evaluate if the memory optimization is needed (e.g. on Mobile VR via Profiler)
Check on *MeshBuilder.cs classes where we leverage new Material() and alter instanciation of materials with same Texture to only once --> Especially useful for TextureArray (World+Items), where we have the same textures for every material and could leverage the same Material.
Dispose these materials (TextureManager, ...) after game stop, as Unity isn't handling it on it's own. https://docs.unity3d.com/ScriptReference/Renderer-material.html Quote: It is your responsibility to destroy the materials when the game object is being destroyed.
Add our usage of material/sharedMaterial as proper code comments or into the Wiki for future references.
Hints:
Whenever we call Renderer.material.* (calling the getter), it will automatically duplicate the material under the hood. Therefore it should be avoided at all costs and Renderer.sharedMaterial.* should be used. https://docs.unity3d.com/ScriptReference/Renderer-material.html Quote: Returns the first instantiated Material assigned to the renderer. Modifying material will change the material for this object only. If the material is used by any other renderers, this will clone the shared material and start using it from now on.
The text was updated successfully, but these errors were encountered:
JaXt0r
changed the title
Every object creates a new Material (+Shader) instance
Check proper usage of _new Material()_ and renderer.
Jun 28, 2024
JaXt0r
changed the title
Check proper usage of _new Material()_ and renderer.
Check proper usage of _new Material()_ and Renderer.material.Set*()
Jun 28, 2024
When the main game is loaded (world.zen; without NPCs), we have over 1.2k Materials initialized. When looked at our mesh creation logic, we always create
new Material(...)
when creating a mesh or calling Renderer.mesh.Set*() when altering data which creates a clone of the Material.TODOs:
Hints:
The text was updated successfully, but these errors were encountered: