x


Using Instantiate on a Rigidbody rather than a whole GameObject

I can copy the Rigidbody of a prefab:

var r = Instantiate(missilePrefab.rigidbody);

but I can't set it on my object:

mymissile.rigidbody = r;

This is just an excerpt. The full story is that in some cases when I Instantiate my missile, I need to Destroy the rigidbody. I want to be able to recreate it, with it's properties set as they were before I Destroyed it.

I guess I'm looking for:

mymissile.AddComponent(r);

But there is no such function (AddComponent takes a string or a type).

more ▼

asked May 17, 2010 at 08:07 AM

Waz gravatar image

Waz
7.2k 66 63 104

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

1 answer: sort voted first

You can't do it - the best you can do is copy the properties, then do a normal AddComponent(Rigidbody) and set the properties yourself

more ▼

answered May 17, 2010 at 09:02 AM

Mike 3 gravatar image

Mike 3
32.9k 19 80 290

I agree with Mike, add a new rigid body and then set its properties from the copy

May 17, 2010 at 09:14 AM spinaljack
(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:

x2808
x2029
x115

asked: May 17, 2010 at 08:07 AM

Seen: 1637 times

Last Updated: May 17, 2010 at 08:07 AM