Instantiate ParticleSystem prefab as ParticleSystem returns null. As GameObject returns the prefab

Hi Guys…

Im trying to instantiate a particle system prefab I made (PSTest) and it’s returning null…
GameObject TempParticle = Instantiate (Resources.Load(“PSTest”), new Vector3 (-2.5f, -2, -5), Quaternion.identity) as GameObject;
Debug.Log (TempParticle);

This is returning the correct object.

But if I use:

ParticleSystem TempParticle = Instantiate (Resources.Load(“PSTest”), new Vector3 (-2.5f, -2, -5), Quaternion.identity) as ParticleSystem;
Debug.Log (TempParticle);

It returns null.

Any Idea what’s happening ??

That’s because you’re trying to convert/cast a GameObject into a Component. Instead, you should get the object first, then get the component afterwards:

GameObject go = Instantiate(spawnObject, transform.position, Quaternion.identity, null) as GameObject;
ps = go.GetComponent<ParticleSystem>();