- Home /
How to Access particleSystemRenderer
Hi! I want to change material properties of my particle. How can i access the material property? In the docs there is :
http://docs.unity3d.com/Documentation/ScriptReference/ParticleSystemRenderer.html
tried:
particleSystem.renderer.material.Color
but that doesnt work, it changes the gameObject's renderer material, not the particles. And no, I cant change it with the color varialbe of the particleSystem, due to many other varialbes in the material that I want to access.
But i cannot access that. It says inherit from renderer, but cant go that way, unity gives me an error.
Is there a way? If this not accessible then why add it to the docs?
Ok, so a workaround is to set color variable name as _TintColor in the shader. That way the start color property in the particle system will change the color of the shader. I would be happy to access other properties of the material though.
you can open used in your case shader source and check for all properties you can change.
Answer by davvilla · May 08, 2013 at 03:38 AM
This is an old question but I was looking for the same answer and I finally figured it out. This worked for me, I hope it still helps or helps someone else!
ParticleSystemRenderer pr = (ParticleSystemRenderer)someGameObject.particleSystem.renderer;
pr.renderMode = ParticleSystemRenderMode.VerticalBillboard;
pr.material.Color = Color.Blue;
This doesn't work anymore with Unity 5.2. The renderer is marked as obsolete and calls an error to the compiler (not a warning as before).
Anyone have any idea how to get the ParticleSystemRenderer with the new system?
This totally works: http://docs.unity3d.com/ScriptReference/Renderer-material.html
Just replace Renderer with ParticleSystemRenderer
Answer by amzin7000 · Nov 26, 2016 at 06:23 AM
The other answer has long been depreciated.
the ParticleSystemRenderer is simply an invisible component attached to the gameobject.
Just use gameObject.GetComponent<ParticleSystemRenderer>()
(where gameObject has a particleSystem component).
The other other answer has now deprecated also. Just use GetComponent<ParticleSystem>().GetComponent<Renderer>()