• 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 BDV · Mar 04, 2015 at 09:50 AM · rigidbodymeshmesh collideraddcomponent

Destroying Rigidbody component (Actor::updateMassFromShapes error)

Hi everybody,

in my scene i need to attach to my 3D model a collider component with rigidbody to catch some collisions. I attached box colliders to my model and then a rigidbody component. After the collisions are catched i dont need rigidbody component anymore. And i need to change box colliders to mesh colliders.

 if (model.transform.childCount != 0) {
             for (int i=0;i<model.transform.childCount;i++) {
                 if (model.transform.GetChild(i).gameObject.GetComponent<MeshRenderer>()!=null) {
                     GameObject.Destroy(model.transform.GetChild(i).gameObject.GetComponent<Rigidbody>());
                     GameObject.Destroy(model.transform.GetChild(i).gameObject.GetComponent<BoxCollider>());
                     model.transform.GetChild(i).gameObject.AddComponent<MeshCollider>();
 
                 }
                 
                 
             }
         }

but when i run this script it gaves me this error Actor::updateMassFromShapes: Compute mesh inertia tensor failed for one of the actor's mesh shapes! Please change mesh geometry or supply a tensor manually! UnityEngine.GameObject:AddComponent()

its caused by this line model.transform.GetChild(i).gameObject.AddComponent();

When i run my script without this line everything works fine ... and when i attach a mesh collider in editor during runtime there is no problem.

Any help ?

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
0

Answer by sniper43 · Mar 04, 2015 at 10:04 AM

My guess is that creating a MeshCollider from scritp is NOT the same as doing it in the editor. My guess for fixing this would be to reference the mesh that needs the collisions mesh:

  model.transform.GetChild(i).gameObject.AddComponent<MeshCollider>();
  model.transform.GetChild(i).gameObject.GetComponent<MeshCollider>().mesh = model.transform.mesh;

A mesh collider is a very processor heavy thing, I'd ratehr recommend you use a primitive collider fot it.

Rigidbody is a tricky thing. But if you want to use it DON'T not use it at times. That is wrong thinking. It is one of the few things that cannot be disabled, and it's that way for a reason.

Either just use regular collisions with OnCollision(), where you don't need rigidbodies or just keep the rigidbody.

Also a tip:

 foreach(Transform child in model.transform)

returns model's transform and all it's child transforms, that you can reference through child.

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

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

21 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

Related Questions

What if the mesh (in mesh collider) does not match visually with the model? 2 Answers

3d Jigsaw puzzle - how to combine dragged objects (Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported in Unity 5.)? 0 Answers

moving hole 3 Answers

Pushing a mesh with mesh collider 1 Answer

How to remove internal triangle/faces when combining mesh 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