Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 unity_g8i91M_UwUm_mQ · Mar 11, 2019 at 01:47 PM · script.basics

Could GameObject have multiple bodies?

Hello all,

I was going through the Unity3D docs and some google search but can not find the answer and understand the mechanics of adding multiple components to GameObject. The whole concept is simple - just use AddComponent<$ComponentType$>() as much as you like and fill your GameObject with features and traits, however there seem (in my view) to be some 'special' cases like this one f.e.:

Could I add more then one Rigidbody2D to single GameObject?

If I can then what of multiple Rigidbodies will return Collider2D.attachedRigidbody when I'll add some? If not then where I could find the info about special cases like that one? Are there any?

Also what will happen if I add Collider2D to GameObject with no body ( Collider2D.attachedRigidbody will be null or same as parent body) and then attach Rigidbody2D? Would the Collider2D.attachedRigidbody change?

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

Answer by TreyH · Mar 11, 2019 at 03:03 PM

Objects can have 1 Rigidbody at-most, but an object can have multiple colliders.

If your goal is to have multiple Rigidbody components governing a "single" object (one limb heavier than another), then you could just attach one to each limb.

You can also check your question pretty easily:

 public class ColliderRigidbodyCheck : MonoBehaviour
 {
     void Start()
     {
         var col = this.GetComponent<Collider>();   
         Debug.LogFormat("[1] Attached rigidbody is null? {0}", col.attachedRigidbody == null);
 
         var rb = this.gameObject.AddComponent<Rigidbody>();
         Debug.LogFormat("[2] Attached rigidbody is null? {0}", col.attachedRigidbody == null);
 
         DestroyImmediate (this.GetComponent<Rigidbody>());
         Debug.LogFormat("[3] Attached rigidbody is null? {0}", col.attachedRigidbody == null);
     }
 }


Which shows that the attachedRigidbody does reflect changes with each call:

alt text


attached-rb.png (10.4 kB)
Comment
Add comment · Show 1 · 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 unity_g8i91M_UwUm_mQ · Mar 15, 2019 at 07:04 AM 0
Share

So is this the only case for unique component in GameObject? Where could I get this information? Or should I "check" any of my basic questions by trial and error in Unity?

PS: Sorry for the delay in response.

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.

Follow this Question

Answers Answers and Comments

109 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

Related Questions

have basic controllers, need flying 1 Answer

Make Object be rendered far away 4 Answers

How to instantiate an object with scripts? 1 Answer

How can I programmatically add comments with the current author, modify date, version after each C# file I change gets saved? 1 Answer

Having trouble accessing a unique instance of a dynamically generated script... 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