Modify [PerRendererData] texture in ParticleSystem (Shuriken)

Hi,

Currently I’m working on a 2d game that can change between day / night cycle.
At night, all foreground object will be changed to dark silhouette.

I achieve this effect by creating custom material that use Sprite/Default shader
and assign this material to all foreground objects. When the cycle change I just need
to change sharedMaterial color of one of the object.

It works beautifully but I encounter problem when I add ParticleSystem since
it seems that it doesn’t provide a way to fill the texture for my material.

I’ve tried attaching this script to the object:


public Texture tex;
ParticleSystem ps;
void Awake () {
    MaterialPropertyBlock mpb = new MaterialPropertyBlock ();
    mpb.AddTexture ("_MainTex", tex);
    ps = GetComponent< ParticleSystem > ();
    ps.renderer.SetPropertyBlock (mpb);
}

But even though the texture of the material is changed, the ParticleSystem
is still emitting a white square.

Is it possible to change the texture this way? Are there any workaround for this?

Thanks.

For those who encounter similar problem.

I still can’t change the texture emitted by ParticleSystem,
but I found a way to achieve same effect (dark silhouette) without changing sharedMaterial.
Instead of using Sprites/Default, use Sprites/Diffuse.

This way you can change all material using Sprites/Diffuse to dark silhouette
with 1 line of code only by changing RenderSettings.ambientLight
and you can use different material for particle, no need for MaterialPropertyBlock.

Regards.

Hi,

there seems to be a problem when setting a material property block on a ParticleSystemRenderer. It is also an issue for me. I need to change a color but I’ll probably do it through the vertex colors. Hopefully Unity will fix this.

That would be psr = GetComponent< ParticleSystemRenderer >();, not ParticleSystem.
But anyway it doesn’t seem to work for me either so I’m getting ParticleSystemRenderer just doesn’t support property blocks :frowning: