Skip to main content
edited tags
Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401
added 1 character in body
Source Link
Arxz
  • 95
  • 1
  • 1
  • 6

Just found creating a material in a script for the first time would have performance impact.
(Using Unity 5.6.5f)

A very simple script for testing is to create a game object with MeshRenderer in Start(), assign a new material each time in Update(),

gameObj.GetComponent<MeshRenderer>().material = new Material(Shader.Find("Standard"));

From Unity Profiler the first function call took much longer than following calls, the first callone took 100ms and others less then 1ms.

Can someone give it an explanation? Thanks.

Just found creating a material in a script for the first time would have performance impact.
(Using Unity 5.6.5f)

A very simple script for testing is to create a game object with MeshRenderer in Start(), assign a new material each time in Update(),

gameObj.GetComponent<MeshRenderer>().material = new Material(Shader.Find("Standard");

From Unity Profiler the first function call took much longer than following calls, the first call took 100ms and others less then 1ms.

Can someone give it an explanation? Thanks.

Just found creating a material in a script for the first time would have performance impact.
(Using Unity 5.6.5f)

A very simple script for testing is to create a game object with MeshRenderer in Start(), assign a new material each time in Update(),

gameObj.GetComponent<MeshRenderer>().material = new Material(Shader.Find("Standard"));

From Unity Profiler the first function call took much longer than following calls, the first one took 100ms and others less then 1ms.

Can someone give it an explanation? Thanks.

Source Link
Arxz
  • 95
  • 1
  • 1
  • 6

Unity run-time creating material has performance impact?

Just found creating a material in a script for the first time would have performance impact.
(Using Unity 5.6.5f)

A very simple script for testing is to create a game object with MeshRenderer in Start(), assign a new material each time in Update(),

gameObj.GetComponent<MeshRenderer>().material = new Material(Shader.Find("Standard");

From Unity Profiler the first function call took much longer than following calls, the first call took 100ms and others less then 1ms.

Can someone give it an explanation? Thanks.