Massive FPS hit when changing colors on the fly

Hi guys,

the following line of code causes a drop of 40 in FPS. It is called every frame.

Obj.renderer.material.color = new Color (1-varCurrent/varMax,0,varCurrent/varMax,0.5f);

Can anyone see right away why this is happening or do I need to post additional Information?

thank you for any help

I can’t see any obvious issue with that code. You are not doing any Debug.Log stuff to check values at all are you? This would hit your frame rate very hard if you are doing it every frame. Could do with seeing more code as this should not give you any noticeable hit even if called every frame. My laptop is Ancient and would run this fine all day long.

The first time you change any material property, a new material instance is generated for that object. The idea is that any changes you make to an object’s material at runtime will only apply to that object. I would only expect a significant FPS drop from this issue if you had a lot of objects. This may or may not be your issue. That is if you call the above line in Start() for all your object (i.e. just once not every frame), then I would expect to see the FPS drop even if the line is not called every frame.

If you are seeing a FPS drop only if this is called every frame, then my material instance idea is likely wrong.

This line was apparently not the culprit. After taking Vector3(0,0,0) and Queternion.identity out of the Obj Instantiate it worked fine.