Particle System pink when attached to a GameObject

12,260

Solution 1

Unity particle system pink squares:

Most likely you haven't selected a material for your particles, or your earlier selection was wiped (for example by moving assets around). That pink color is how Unity indicates that there was a problem getting the material for the particle system. You can fix this by selecting a new one, or reselecting the particle texture that you used before.

Around the bottom of the particle object's inspector there should be a section called renderer, where you can select a new material. It is the last tab in particle-system.

enter image description here

For now you can fix this by clicking on the material field in renderer and locating the default particle. You can use other materials too if you want.

If you created the particle system via script you will have to see @Programmers answer, but it will still come down to a missing material.

Solution 2

The problem is a missing material due to how you created the particle.

There are two ways to create Particle System:

1.Create empty GameObject, select it then go to Component --> Effects and add the Particle System component to that empty GameObject. This is how you created your current Particle System.

If you create your Particle System with method #1, Unity will not attach material to the Particle System therefore making it to be pink. You will have to create a new Material, change the shader to "Particles/Alpha Blended Premultiply" and use the "Default-Particle" as the texture to make the particle look like the default material.

You can also just use the "Default-Material" for the Particle System but you can't modify it.

enter image description here

2.Create particle by going to GameObject ---> Effects ---> Particle System.

If you create your Particle System with method #2, Unity will create new GameObject, attach a Particle System and also a material to it.

Always create your material by going to GameObject ---> Effects ---> Particle System. It will save you some time.

The simple solution is to delete your current particle GameObject, create new one by going to GameObject ---> Effects ---> Particle System instead of the method described in #1.

If you need to create Particle System from code then do what I said in method #1 but via script. Here's how to do that:

void Start()
{
    createParticleSys();
}

void createParticleSys()
{
    //Create GameObject to hold the Particle System
    GameObject psObj = new GameObject("Particle System");
    //Add Particle System to it
    ParticleSystem ps = psObj.AddComponent<ParticleSystem>();

    //Assign material to the particle renderer
    ps.GetComponent<Renderer>().material = createParticleMaterial();
}

Material createParticleMaterial()
{
    //Create Particle Shader
    Shader particleShder = Shader.Find("Particles/Alpha Blended Premultiply");

    //Create new Particle Material
    Material particleMat = new Material(particleShder);

    Texture particleTexture = null;

    //Find the default "Default-Particle" Texture
    foreach (Texture pText in Resources.FindObjectsOfTypeAll<Texture>())
        if (pText.name == "Default-Particle")
            particleTexture = pText;

    //Add the particle "Default-Particle" Texture to the material
    particleMat.mainTexture = particleTexture;

    return particleMat;
}
Share:
12,260
I AM A Hacker
Author by

I AM A Hacker

Updated on August 14, 2022

Comments

  • I AM A Hacker
    I AM A Hacker over 1 year

    I am working on unity particle system.

    I created a new project and an empty object then added the Particle System to it. For some reason it not working properly you can see the image attached to see whats happening...

    enter image description here

  • AresCaelum
    AresCaelum almost 6 years
    As stated in my comment on the OP's question, a pink texture does not mean a null material, it means there is an error with the material, whether the material is null or the shader referenced by the material has a compile error.
  • Tyler S. Loeper
    Tyler S. Loeper almost 6 years
    @Eddge, I have made the change.
  • Tyler S. Loeper
    Tyler S. Loeper over 4 years
    This is the most common scenario where this is going to happen. Technical issues where the particle cant be rendered or the base file is missing, or anything else of that nature is by far going to be the exception.