[SOLVED] Clone Objects taking over heirarchy

Hello,

I just noticed a moment ago as I was playing through a level on Block Breaker that as soon as bricks were being destroyed and instantiang their particle systems they remained active in the Heirachy - and was a bit shocked :astonished:. Can someone please point me to the lectures where Ben discusses removing these cloned object?

As always thankyou in advance.
Regards.

I dont believe its covered, the question has come uo a couple of times.

You can call Destroy on the particles with a delay, so use the duration of the particles for that and you should be set :slight_smile:

They will of course all be mopped up when the scene changes.

I really thought it was covered and I missed it - it must’ve been some other topic that was doubling up in the Hierarchy.

I wasn’t really concerned about the amount of prefabs being left on the hierarchy to do with the brick destruction - although there were quite “a lot”, it’s just that I am about to attempt to use “working” bullets and at the minute every time I hit the mouse button two prefabs are being created, not, moving so far, but, soon, hopefully, and the amount of prefabs on screen is about the explode exponentially! I thought about doing an exercise in how many prefabs could be left in the hierarchy before Unity 4.6.1 had a cow :grinning:, but thought better of it.

I’m good like that :stuck_out_tongue_closed_eyes:.

EDIT: I just tried using the destroy method ala:

Destroy(explosion.gameObject, 1.5f);

just after it was instantiated and Unity threw up this error as it hit the first yellow block:

Destroying assets is not permitted to avoid data loss.
If you really want to remove an asset use DestroyImmediate (theObject, true);
UnityEngine.Object:Destroy(Object, Single)
HitBrick:OnCollisionEnter2D(Collision2D) (at Assets/HitBrick.cs:104)

So, what is the best method of implementing the killing off of these clone objects.

Sorry for the triple post. But, don’t worry about it, after copious googling of the Unity questions site I found two methods of doing what I wanted:

One was instantiating the explosion as a gameObect and deleting that object with the destroy function after a specified time:

GameObject clone = (GameObject)Instantiate (explosion, transform.position, Quaternion.identity);
Destroy (clone, 1.5f);

The other was:

Destroy(GameObject.Find("expolsion(Clone)"),1.5f);

Now, I need a to go and bang my head into a brickwall :confounded:.

Privacy & Terms