- Home /
How to enable/Disable/enable the Particle System Component of a child object on the same object/Parent? (Solved)
I can officially say there 'is' such a thing as information overload, geez I must have read about 40 topics/answers now and I'm still no clearer to solving my issue.
I have a particle System attached to a child object of my player (hierarchy wise that's Player/MainCamera/BoostEffectObject/ParticleSystem
My script is on the player object (parent of the child object)
I think (please correct me if wrong) that I need this to initialise-
void Awake()
{
boostSparkle = GetComponentInChildren<ParticleSystem>();
}
and then I have this in my OnTriggerEnter function -
boostSparkle.SetActive(true);
But I'm getting this error -
"Assets/Scripts/SpeedBoostActivate.cs(32,38): error CS1061: Type UnityEngine.Component' does not contain a definition for
SetActive' and no extension method SetActive' of type
UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)"
I've tried different variations and variations using enabled but everything seem to give a compiler error.
Suggestions please guys
???
Answer by siaran · Feb 20, 2015 at 02:43 PM
You have a reference to the particlesystem, not the gameobject, and particlesystem has no SetActive method. Instead, use bootSparkle.gameObject.SetActive(true)
to activate the gameObject. Alternatively, you could just have the gameObject active, disable the emission, and in your code call bootSparkle.enableEmission = true
.
Is the gameObject that contains your particleSystem active? What I meant by disabling the particle system's emission is, go to your particleSystem, then uncheck the 'emission' checkbox.
Ah, I see. I'd assumed you just had a looping particlesystem and that the time didn't really matter (that's how I use them the most).
What I think you want to do is set your particlesystem so that -play on awake is disabled -emission is enabled -disable looping -call particleSystem.Play() when it should start playing ins$$anonymous$$d of setting enableEmission to true. (and maybe also .Stop() when it should stop. I dunno, I never use those functions.)
I forgot returns don't work, reformatted how I said you should set up your system:
play on awake is disabled
emission is enabled
disable looping
call particleSystem.Play() when it should start playing ins$$anonymous$$d of setting enableEmission to true
...okay, I'm out of ideas on how to get the particlesystem to reset, so how about this: ins$$anonymous$$d of trying to reset your attached particlesystem, put your particlesystem on a prefab, then instantiate that prefab on the trigger (and just have it pla y on awake and have it destroy itself once the particlesystem is done playing). edit:
Something like
public GameObject boostSparkles;
void OnTriggerEnter(Collider collider){
GameObject go = (GameObject) Instantiate(boostSparkles, transform.position, transform.rotation);
//set sparkle effects parent to this transform
go.parent = transform;
//Destroy after 5 seconds
Destroy(go, 5.0f);
}
ah, it should be go.transform.parent ins$$anonymous$$d of go.parent
Answer by Shaq · May 29, 2017 at 06:29 AM
I had the same issue, so created empty game Object and placed particles in there
Then just the enabled/disabled the game Object