• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by ham · Feb 26, 2014 at 05:10 PM · physicsrigidbody

disabling rigidbody2D via script

hi guys i want turn the rigidbody off via script ...and i try this

  this.rigidbody2D.enabled = false ;

but this is the unity error

MissingFieldException: UnityEngine.Rigidbody2D.enabled Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates)

would anybody help me...

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image luquio · Mar 07, 2015 at 05:31 PM 0
Share

i also tried this to stop an enemy when it is killed, but it keeps moving until the gameobject gets destroyed (2f) rigidbody2D.is$$anonymous$$inematic = true;

1 Reply

· Add your reply
  • Sort: 
avatar image
11

Answer by robertbu · Feb 26, 2014 at 05:16 PM

The Rigidbody class does not have an enabled flag. The typical solution is to set the isKinematic flag. This will freeze the object in position.

 rigidbody2D.isKinematic = true;

If you won't be using the Rigidbody in the future you can remove it:

 Destroy(rigidbody2D);
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Linus · Feb 26, 2014 at 05:20 PM 0
Share

rigidbody2D

avatar image ham · Feb 26, 2014 at 06:36 PM 0
Share

thanx i could delete the Rigidbody2D component , but the problem is that i want use it in the next period of time , so would u tell me that how can i add it again i used these 2 codes but Unfortunately none of them worked..

 this.AddComponent(Rigidbody2D);   
 this.AddComponent.<Rigidbody2D>();
 

...and thanx again

avatar image robertbu · Feb 26, 2014 at 06:42 PM 0
Share

@Linus - missed that it was 2D (thanks), but the answer is the same. You cannot disable a rigidbody2D.

@ham - 'this' is a reference to the current script. Try this (I just tested it to make sure it worked):

  gameObject.AddComponent(Rigidbody2D);
avatar image d2clon · Jan 23, 2021 at 04:39 PM 0
Share

Remember to reset velocity rigidbody2D.velocity = Vector2.zero;

avatar image CoolTube_YT1234 · Oct 21, 2021 at 11:07 PM 0
Share

@robertbu Is there a way to disable the simulated box, this way it won't have colliders either?

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to limit the motion direction of a GameObject? 1 Answer

How to make foot don't cross the ball? 0 Answers

Camera gets flung off of the map when the player collides with certain objects. 0 Answers

How to make Rigidbody.AddForce less delayed in Unity3D? 0 Answers

Avoid bouncing when ground move down 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges