How to change ParticleSystem Material Texture in Code

Hi!

I try to do the following:
If my object has a collision, I want to Instantiate a ParticleSystem Prefab.
This Prefab already has a Material assigned with the Shader “Particles\Alpha blended”.
Now after instantiating I change the Texture of the Material with the following Code:

newInstance.GetComponent().material.mainTexture = myTextures*;*

However the particles stay white. And if I check in the Inspector at runtime, there are two Materials now: The existing one of the Prefab with no Texture, and a new one with the wrong Shader and the Texture I just assigned. See attached Image.

How can I implement it that I can assign a different Texture for every new ParticleSystem Prefab I instantiate?

Many thanks in advance!
Best regards

2641085--185893--particle.png

Well I know why I didn’t get an answer now.
Actually there was nothing I did wrong in the code.
It seems to be a bug in Unity.
Usually if you Change the Renderer Material Property, it also changes the Material you see further down below.
However somehow the Renderer Material and the Material further down started to lead separate lives.
So I always had two Materials on my ParticleSystem instead of just one.
Both materials where visible in the Debugger as well as in the Game at runtime.

What i had to do is building a new Particle System, Setting every property the same, Setting a new Material and I only had one Material now.

See attached Picture for the bug.