# Particle system color not set properly in Android build in Unity.

I want to set the color of "Particle System" that I add to a game object in run time. Both game object and particle system are created in run time too.

I have the following code that works well on PC when I run it... But the problem is that in "Android" builds, color does not set correctly and particles are always "pink".

It should be:

But in Android it seen as:

Here is the code I use:

GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = new Vector3(x, y, z);
var ps = sphere.GetComponent<ParticleSystem>();
ps.startSpeed = 0.01f;
ps.startSize = 0.03f;
ps.maxParticles = 10000;
ParticleSystemExtension.SetEmissionRate(ps, 10000);
var sh = ps.shape;
sh.shapeType = ParticleSystemShapeType.Circle;

var cbl = ps.colorOverLifetime;
cbl.enabled = true;
Color mater = Color.green;
cbl.color = new ParticleSystem.MinMaxGradient(mater);


Oh God! I change my solution and it work fine!

At first I make an empty GameObject with ParticleSystem attached, then create a prefab of that. after that, I add this prefab to my scene and set the necessary properties to it and then deactivate that.

In my script, add a public GameObject and assigned it to my gameObject (called Ring) that was created before.

Then instatiate it by the following code:

GameObject ps = Instantiate(Ring);


then make ps the child of spheres that I was creating in code:

 Ring.GetComponent<ParticleSystem>().startColor = Color.green;
GameObject ps = Instantiate(Ring);
ps.transform.parent = sphere.transform;
ps.transform.localPosition = Vector3.zero;
ps.SetActive(true);


And that's it! It works nice!