Search Unity

Batching does not work. Showing Objects have different MaterialPropertyBlock set

Discussion in 'Shaders' started by milosp, Jan 12, 2020.

  1. milosp

    milosp

    Joined:
    Dec 31, 2012
    Posts:
    23
    I thought that is the point of the whole MaterialPropertyBlock - differnet MatrialPropertyBlock and everything else the same. The code looks like this:

    Code (CSharp):
    1. Renderer renderer = GetComponent<Renderer>();
    2. MaterialPropertyBlock propBlock = new MaterialPropertyBlock();
    3. renderer.GetPropertyBlock(propBlock);
    4. propBlock.SetTexture("_MainTex", thumbTex);
    5. renderer.SetPropertyBlock(propBlock);
    and shader is a simple Unlit shader with
    Code (CSharp):
    1. Properties
    2. {
    3.   [PerRendererData]_MainTex ("Texture", 2D) = "black" {}
    The frame debugger still shows these as individual draw calls and does not batch them and reason is
    "Objects have different MaterialPropertyBlock set"
     
    Tony_Max likes this.
  2. Dorodo

    Dorodo

    Joined:
    Mar 8, 2015
    Posts:
    44
  3. milosp

    milosp

    Joined:
    Dec 31, 2012
    Posts:
    23
    That makes sense. Thank you