Search Issue Tracker

By Design

Votes

1

Found in

2019.4

2020.3

2020.3.17f1

2021.1

2021.2

2022.1

Issue ID

1361061

Regression

No

Renderer.SetPropertyBlock behaviour differs when an integer is passed as a parameter

Shader System

-

How to reproduce:
1. Open the user's attached project
2. Press the Play button
3. Observe the Cubes changing colour in the Game view
4. Press the Play button to stop playing
5. Select either "Cube1" or "Cube2" in the Hierarchy window
6. In the Inspector window, observe the Material properties by expanding the Material component (click on triangle arrow)
7. Press the Play button
8. Observe the Game view

Expected result: both Cubes change colours identically
Actual result: the Cubes change colours at different speeds

Reproducible with: 2019.4.30f1, 2020.3.18f1, 2021.1.21f1, 2021.2.0b12, 2022.1.0a8

Notes: On 2019.4.30f1, 2020.3.18f1 and 2021.1.21f1, the behaviour changes only after opening the Material properties in the Inspector

  1. Resolution Note (2022.1.X):

    This seems to be the design of material block properties.
    When setting a material block property without an index, this overwrites the "Per Renderer" block, but when setting it with an index it overwrites the "Per Material" block.
    So what's happening in the given project is that the animation is overwriting the "Per Renderer" value for "_EmissiveColor". When the provided script does the call of:
    ```
    GetPropertyBlock(block);
    block.SetColor("_Color", ...);
    SetPropertyBlock(block);
    ```
    this is reading the "Per Renderer" block which has the altered "_EmissiveColor". However when doing:
    ```
    GetPropertyBlock(block, i);
    block.SetColor("_Color", ...);
    SetPropertyBlock(block, i);
    ```
    This is reading the "Per Material" property block which does not have the changed value for "_EmissiveColor". The renderer seems to use the "Per Material" block if it exists, otherwise it falls back to the "Per Renderer" block, but it doesn't merge the blocks together. This can be verified by the adding some debugging akin to:
    ```
    renderer_.GetPropertyBlock(perRendererBlock);
    renderer_.GetPropertyBlock(perMaterialBlock, 0);
    Debug.Log($"_EmissionColor: {perRendererBlock.GetColor("_EmissionColor")} {perMaterialBlock.GetColor("_EmissionColor")}");
    ```
    And you'll see that the value is changing for the per renderer block, but not the per material block.

    This could maybe use some improved documentation, or an option for animations to target a per material block instead of the renderer one.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.