Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

How to change Material Property Block for Particle System?

Discussion in 'Scripting' started by Ziya, Aug 23, 2019.

  1. Ziya

    Ziya

    Joined:
    Aug 30, 2013
    Posts:
    61
    Why does changing Texture of Particle System using Material Property Block changes texture, but Particle System is still emitting old texture?

    I try the code in Start, checking in Editor shows new texture, but Particle System still emits old texture. The script works for SpriteRenderer, but not ParticleSystem. I tried to Play/Stop emission - no difference.

    Code (CSharp):
    1.     ParticleSystemRenderer renderer = gameObject.GetComponent<ParticleSystemRenderer>();
    2.     MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();
    3.     renderer.GetPropertyBlock(materialPropertyBlock);
    4.     materialPropertyBlock.SetTexture("_MainTex", texture);
    5.     renderer.SetPropertyBlock(materialPropertyBlock);
     
    Last edited: Aug 23, 2019