mainTextureOffse causes performance issue. How to resolve it ?

Hello, when this script is activated, I have low framerate and performance issue.

public class turn_texture : MonoBehaviour {

    public float offset;
    public float speed;

    public float reset;
   

    void Start () {


   
    }

    void Update() {

        if ( offset < 0.3f){
       
            float zag = Time.timeSinceLevelLoad - reset;
            offset = zag * speed;
            this.renderer.material.mainTextureOffset = new Vector2(0, offset);
   
        }

        else {

            this.renderer.material.mainTextureOffset = new Vector2(0, 0);
            offset = 0;
            reset = Time.timeSinceLevelLoad;

        }
    }
}

Can someone explain me why, and how to resolve it plz ?

How many objects do you have with this texture?

I have one single object with this script and it is instanced every 1 seconde (and every instance is destroyed after 7 secondes, so I have 8-9 objects with this texture at the same time).

9 doesn’t seem like too much but it could be that when you change the material property then unity creates a new material for each object, which increases the number of draw calls. Maybe try using .sharedMaterial if possible.

I replaced this.renderer.material.[mainTextureOffset by this.renderer.sharedMaterial.mainTextureOffset but no changements :frowning:](Unity - Scripting API:)

Try setting the offset in the shader itself.