• 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 /
  • Help Room /
avatar image
Question by $$anonymous$$ · Dec 02, 2016 at 10:10 AM · c#rigidbodyobjectskinematic

change rigidbodies in all objects to kinematic

how do I get all rigidbodies from all objects in the scene and change them to kinematic through c#? tried this, not sure whether its the correct way, but it only changes the one in object that's added last in the scene:

 Rigidbody[] rb = Rigidbody.FindObjectsOfType(typeof(Rigidbody)) as Rigidbody[];
 foreach(Rigidbody body in rb)
 {
    body.isKinematic = true;
 }

Comment

People who like this

0 Show 2
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 TBruce · Dec 02, 2016 at 06:53 PM 1
Share

This depends if you want to changed the at game start (that would mean the modification/change would be temporary and would revert when game ends) or if you want to make a permanent change before game starts.

Just by allowing your code to execute in Awake or Start will perform this task for you, buf if you desire the latter (make the change permanent) you can go one of two ways - create a Menu Item (preferred) or create a button that displays in the inspector.

avatar image ThePersister TBruce · Dec 03, 2016 at 11:12 AM 0
Share

Good point @Mavina, I totally asumed felsiska meant runtime, but obviously editor time would be useful as well! Good catch ;)

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by ThePersister · Dec 02, 2016 at 10:32 AM

Hi @felsiska,

Your code seems to work just fine! https://gyazo.com/9c98f42c68342c939d6dbf0aa157ff63

The only thing I can imagine is that you call it too soon, or you have other code that prevents or influences the isKinematic variable in a different way.

Try using it in an empty scene and you'll see it works.

Try to:

  • Find other code that edits the isKinematic variable.

  • Try to set a different set of rigidbodies that aren't used anywhere else.

  • Debug the state of isKinematic, does it get set to true, and what is the name of that rigidbody's object.

See if you can find out more, but you're on the right track!

I hope that helps, if it does, please accept this answer, it'd be much appreciated!

If you need any more details or if you find out more with which I can help, let me know! :)

.

Best of luck!

Cheers,

ThePersister

Comment

People who like this

0 Show 2 · 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 $$anonymous$$ · Dec 05, 2016 at 01:21 AM 1
Share

thx a lot! I tried on empty scene and works. will double check on other overlapping commands. does Object.FindObjectOfType only works on one object in the scene?

avatar image ThePersister $$anonymous$$ · Dec 05, 2016 at 09:55 AM 1
Share

Yes it does! Make sure to use:

FindObject*s*OfType instead of FindObjectOfType.

If you want multiple objects, your original post indicated that you were though!

For Single Object: https://docs.unity3d.com/ScriptReference/Object.FindObjectOfType.html

For Multiple Objects: https://docs.unity3d.com/ScriptReference/Object.FindObjectsOfType.html

Note that Fidn object of type doesn't work on inactive objects, so if you have any inactive rigidbodies to update you might want to apply a different method of referencing them! :)

If you need anything else let me know!

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

270 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 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 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 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 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 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 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 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 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 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 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 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

Freezing an object and keeping it's velocity 1 Answer

Rigidbody is colliding terrain on isKinematic = false. call although meshes don't touch 0 Answers

Best way to pick up objects in unity? 2 Answers

,Why is my character sliding? (Rigid Body) 0 Answers

Ray cast to object to transform, instead all objects with script transform. 0 Answers


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