Search Unity

Changing SpriteRenderer MPB distorts sprite

Discussion in 'Scripting' started by xjjon, Jan 3, 2020.

  1. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    612
    Would anyone know why changing the color of a sprite using the material property block of the renderer will distort it?

    ```
    var renderer = GetComponent<SpriteRenderer>();
    MaterialPropertyBlock mbp = new MaterialPropertyBlock();
    mbp.SetColor("_Color", color);
    renderer.SetPropertyBlock(mbp);
    ```

    upload_2020-1-2_21-12-28.png

    White one is not modified, red one is after color is applied.

    Of course, this can be avoided by using `SpriteRenderer.color` instead but just curious as to why this happens. Thanks.