- Home /
How do I set a Particle System Material Using Code?
I am a bit of a coding novice and often have a hard time figuring out how to adjust certain components using script. What I have is a Reticule for a 2D game that projects a ring at the mouse location when I click. I would like the physical particle to be customizable in game.
I have had little issue up to this point. I have found and assigned the component, but for some reason, whenever I try to set the material of the Particle with the script, the component the script found disappears. I'm guessing it is because the script below tries to set the actual "Reticule" (ParticleSystemRenderer) into the "Ring_Material", and so it vanishes. However, I'm not sure why this happens as I added the ".material". So surely it should set the material to "Dashed" and not attempt to set the Particle system to it.
if (Reticule == Reticule_Type.Dashed) {
DE_Script.Reticle.material = DE_Script.Ring_Material [0];
Is this a glitch, or an error on my behalf? I can't seem to otherwise find a way to set the particle material in the particle system. I also am certain it does find the component as it is there when start the game up, it only disappears when the code I am showing activates.
Your answer
![](https://koobas.hobune.stream/wayback/20220612075445im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Renderer Removed When Scene Started 0 Answers
How to FadeIn 3dObject using alpha color? 1 Answer
Material Change Color on trigger. 1 Answer