- Home /
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.
Answer by melonkuantum · Apr 11, 2014 at 04:32 PM
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.
Answer by Razieln64 · May 09, 2014 at 03:07 AM
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.
Answer by benblo · Dec 04, 2014 at 02:57 PM
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 :( ...
Your answer
Follow this Question
Related Questions
Materialpropertyblock cannot work at ParticleSystemRenderer's 「Mesh」RenderMode? 1 Answer
SetPropertyBlock doesn't work for particle systems? 0 Answers
Spawning Particle Systems for Gun Sparks 1 Answer
Particle Collision Mesh Occlusion 1 Answer
What would be the "next-best-thing" to a ParticleSystem? 1 Answer