I have a GameObject "FireBall" with a ParticleSystem attached to it. I want to add the same ParticleSystem to other GameObject "Avatar". Initially there is no ParticleSystem attached to "Avatar".

When I do this -

ParticleSystem fireparticlesyst = gameObject.AddComponent<ParticleSystem>();

It adds a ParticleSystem to "Avatar" but I want to set all the properties of this ParticleSystem to the ParticleSystem attached to "FireBall".

If I add all the properties by individually I can't set some of the properties as they are read only.

How to do this ?


A simple workaround to do so is:

1- Make an empty GameObject with ParticleSystem attached.

2- Make prefab of that. Borrow that prefab as public GameObject in your script.

3- Instatiate as GameObject in your script.

4- Make child of FireBall and other GameObjects as well.

public GameObject _particleSystem;

void CreatePS()
    //Instantiate _particleSystem as new GameObject.
    GameObject ps = Instantiate(_particleSystem);

    // Set new Particle System GameObject as a child of desired GO.
    // Right now parent would be the same GO in which this script is attached
    // You can also make it others child by ps.transform.parent = otherGO.transform.parent;
    ps.transform.parent = transform;

    // After setting this, replace the position of that GameObject as where the parent is located.
    ps.transform.localPosition = Vector3.zero;
  • \$\begingroup\$ GO to which I want to attach this particlesystem is a movable GO, after doing these steps the particlesystem is coming in the screen but its not moving with the GO. \$\endgroup\$ – Shantanu Singh Dec 30 '15 at 7:57
  • \$\begingroup\$ Make sure in hierarchy that you have set the correct parent \$\endgroup\$ – Hamza Hasan Dec 30 '15 at 8:27
  • \$\begingroup\$ can you show your code? \$\endgroup\$ – Hamza Hasan Dec 30 '15 at 9:06
  • \$\begingroup\$ pastebin.com/qfjedzZA check "FireBall" function \$\endgroup\$ – Shantanu Singh Dec 30 '15 at 9:12
  • \$\begingroup\$ I think ps.transform.parent = transform; will work instead of ps.transform.parent = transform.parent;. It was a mistake. Check the edited answer \$\endgroup\$ – Hamza Hasan Dec 30 '15 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.