• 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
0
Question by Alienjesus · Apr 03, 2011 at 02:58 PM · arraychildrenfor-loopkinematicrigidbodies

Find children and set them all to be kinematic rigidbodies

OK, before we start, I know you shouldn't really have rigidbodies on children, but I'll try my best to explain why I do.

I'm making a game where you can move objects around to progress. One of these objects is a pencil pot, and it's full of pencils, rulers and the like. When you pick up the pencil pot, I want it to bring all the stationary inside it along with it. However, I also wish for these objects to be able to be picked up out of the pot and moved around independently, which is why they have their own rigidbodies.

When I pick up an object in my code, it sets the object to kinematic and turns collisions off on the object. Because of this, when I pick up the pot, all the pens and whatnot fall through because they still have gravity applied to them and the object they were sitting in is no longer solid. I've tried the obvious method of setting the pencils to be kinematic by default, but unfortunately my game doesnt seem to like that, as my pencil pot goes crazy and vibrates its way across the desk that it's on.

Because of all this, I want to find a way to access all of the children of the pot when I pick it up, and set them to all be kinematic too. I can't figure out how i'd do this. There doesn't seem to be simple setting to change all children, so I'm assuming I need a for loop to cycle through the children and set each one in turn, but unfortunately I can't figure out how to set up the array I'd need to do so.

If theres a more elegant/obvious way around this, I'd love to know! All help is appreciated, thanks!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Owen-Reynolds · Apr 03, 2011 at 04:22 PM

In http://answers.unity3d.com/questions/22767/how-to-see-if-transform-has-child the poster has copied the "see all kids" code from the Unity scripting docs. The answer has some more examples of doing stuff to your kids (some I haven't seen in the docs!)

Comment
Add comment · 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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Check whether all game objects with a tag have been destroyed 2 Answers

Push down GUI everytime for loop cycles through Array 1 Answer

Tower defense, turret aiming wrong. 1 Answer

Object reference not set to an instance of an object with object set, 1 Answer

For In Loop Fills all values in arrays problem 2 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