disable rigidbody component (not working in Unity 5, Editor & C#)

Hello everyone!
I just tried to disable the rigidbody component, but I keep getting errors.
This is the code I tried to use in the beginning:

this.gameObject.GetComponent<Rigidbody>().enabled = false;

Some other approaches didn’t work either:

this.gameObject.GetComponent.<Rigidbody>().enabled = false;
this.gameObject.GetComponent(Rigidbody).enabled = false;
this.gameObject.GetComponent.(Rigidbody).enabled = false;

Also, I noticed the checkbox for the rigidbody component is missing.
So I can’t even disable the component in the Editor.

Am I something missing?
The problem occurs on Unity 5.0.1p2.

I did see missing checkboxes for components before and wondered why they were gone. But that happened mostly with scripts attached to gameobjects, which I didn’t need to disable at that point, though.

Many thanks in advance,
Greetings,
Shu

Did you figure this out? I’m having the same problem in unity 5.2. I need to disable the rigidbody when our player dies.

@clearrose
I’m not entirely sure how I solved it, but I remember two solutions to that:

Destroying the whole component:

Destroy(GetComponent<Rigidbody>());

or
Making the rigidbody sleep*:

.GetComponent<Rigidbody>().Sleep();

*for “at least one frame”: Unity - Scripting API: Rigidbody.Sleep

EDIT:
I might have used isKinematic:

.GetComponent<Rigidbody>().isKinematic = false;

While, this did what it was suppose to but, when the player revives i need the component back. this causes problems because the player is swimming and i need the gravity set to zero. I tried using gravity scale, but that didn’t work:

Rigidbody2D.gravityScale = 0;

When tested i was still able to move the player with user input.

[

I already had this in place to stop the physics engine from making the player float and rotate around after he died. But, the problem still exists where the user can move the player back and fourth with input.

I figured it out thanks, I fixed it using a boolean “IsDead”.

1 Like