x


"Some objects were not cleaned up when closing the scene"

I have a "Giblets" script which OnDestroy clones parts of the gameObject I'm destroying, gives them a rigidbody, and then throws them into the air.

There are two problems with this. First one is when I stop the scene I get the above error message, and they are still in my Hierarchy. Second problem is that even with the rigidbody they fall right through the floor. Any ideas?

Here's the code:

public class Giblits : MonoBehaviour {
    public GameObject[] giblets;

    void OnDestroy() {
        GameObject instaGib;
        foreach (GameObject gib in giblets) {
            instaGib = (GameObject) Instantiate(gib, gib.transform.position, gib.transform.rotation);
            instaGib.AddComponent("Rigidbody");
            Vector3 force = new Vector3(Random.Range(-5,5), Random.Range(15,25), Random.Range(-5,5));
            Vector3 torque = new Vector3(Random.Range(-5,5), Random.Range(-5,5), Random.Range(-5,5));           
            instaGib.rigidbody.AddForce(force, ForceMode.Impulse);
            instaGib.rigidbody.AddTorque(torque, ForceMode.Impulse);
            Destroy(instaGib, 3);
        }
    }   
}
more ▼

asked Mar 15 '11 at 12:56 AM

Patyrn gravatar image

Patyrn
542 49 54 64

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I was having the same trouble. This answer to another question should solve your issue. http://answers.unity3d.com/questions/54674/is-there-a-way-to-know-when-the-application-is-in.html

more ▼

answered May 25 '11 at 10:58 PM

Antony Blackett gravatar image

Antony Blackett
981 9 12 19

Sweet this looks like exactly what I need.

May 26 '11 at 05:46 PM Patyrn
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2087
x1792
x764
x18

asked: Mar 15 '11 at 12:56 AM

Seen: 2327 times

Last Updated: May 26 '11 at 05:46 PM