#ok so the explosion is the gameobject

1 messages · Page 1 of 1 (latest)

snow aurora
#

Your Explosion component is attached to a GameObject

#

there is also a ParticleSystem on that GameObject

elfin stone
#

ye

snow aurora
#

Your code is only destroying the ParticleSystem

#

leaving everything else behind

#

You're instantiating a prefab, right?

elfin stone
#

yes

snow aurora
#

Then your script will be affecting just the instance that was created

#

so destroying that GameObject will get rid of the instance

elfin stone
#

okay and i dont understand how do i get the other instances

#

i am creating them with instantiate, no?

snow aurora
#

Yes, and then each one is, individually, going to destroy itself when it's done, right?

elfin stone
#

its supposed to i guess

#

but it doesnt

snow aurora
#

Because it's only destroying the particle system

#

The game object has several components on it -- the particle system, your explosion script, and maybe some others

#

If you do Destroy(particleSystem), you will only destroy the particle system component

#

The explosion script will still be attached, and the entire game object will still exist

elfin stone
#

yeah i dont wanna destroy the game object because its a gamemanager

snow aurora
#

Is it really, though?

#

I thought you were instantiating explosion prefabs.

#

ah, I see the confusion

elfin stone
#

yes it would be better from another script but i cant change the prefab script anymore

snow aurora
#

you're thinking I'm saying to do this

#
Destroy(gameObject);
#

I was also a bit confused; I thought that the Destroy was being run by the explosion prefab

#

but no, it's being run by the manager script

#

Consider this:

#
Destroy(explosionInstance.gameObject, 2);
#

this will tell Unity to destroy the entire explosion object in 2 seconds

elfin stone
#

ah

#

i thought the particle system is the same as a gameobject already

snow aurora
#

ah, no, they are distinct

#

ParticleSystem is a component

#

You can Destroy() any kind of unity Object

elfin stone
#

it tells me this

snow aurora
#

Show me what code you ran

elfin stone
snow aurora
#

you may have done Destroy(explosion.gameObject);

#

yes

#

that tried to destroy the prefab

elfin stone
#

oh

#

yea

snow aurora
#

which Unity doesn't let you do, so that you don't actually lose the asset

#

explosionInstance is a reference to the ParticleSystem on the prefab you just created

elfin stone
#

that would be a crazy mistake lol

snow aurora
#

yeah, you can do a lot of damage if you start messing with the assets themselves :p

#

but there are guardrails, like the one you saw

elfin stone
#

aaah yes now it works

#

so i need to make sure i actully destroy the gameobject

snow aurora
#

right

#

you can destroy individual components, or you can destroy the gameobject

elfin stone
#

interesting

snow aurora
#

(you can't destroy the transform, though; that's not allowed)