- Home /
Parenting instantiated particle system
Hi everyone - I have a particle system that is instantiated when another object collides with it - however I want it to move with the parent it is a child to. This is the current code I have, but it doesn't seem to be following the parent, just stays in the place it was instantiated. Thank you!
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ParticleInstantiate : MonoBehaviour {
public GameObject transmissionParticles; public GameObject parentObject;
void OnCollisionEnter (Collision coll) { if (coll.collider.CompareTag ("Transmission")) { Transmit (); Debug.Log("collided"); } }
void Transmit () { GameObject transmission = Instantiate(transmissionParticles, transform.position, transform.rotation); transmission.GetComponent().Play(); transmissionParticles.transform.parent = parentObject.transform; }
}
Answer by kot2202 · Jul 15, 2020 at 05:29 PM
You instantiate 'transmission' GameObject transmission = Instantiate(transmissionParticles, transform.position, transform.rotation);
but set transform of the 'transmissionParticles' which is your prefab I believe. transmissionParticles.transform.parent = parentObject.transform;
transmission.transform.parent = parentObject.transform;
should work
Your answer
Follow this Question
Related Questions
Manipulating Instanced Object 2 Answers
Silly Instantiation Issue 0 Answers
Parenting an instantiated Prefab? 1 Answer
Insantiate object to parent without changing scale? 0 Answers
Strange movement artifacts when rotating children around parent object 1 Answer