Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 DoctorWhy · Feb 19, 2013 at 05:47 PM · tensor

Setting the tensor manually

This error has been annoying me for a very long time, and I can not find a proper answer to it. It is the really annoying 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.MeshCollider:set_sharedMesh(Mesh)

A lot of people are saying to turn the mesh collider into a box collider, but that is not a possibility here. So, I try and do what it suggests right before the line that is throwing this error.

 //This updates the collisionMesh based on the animations and what not
 UpdateMesh();
 // not sure why this is necessary, but it is
 meshCollider.sharedMesh = null;
 
 //The meshRigidBody is the meshCollider.rigidBody
 meshRigidBody.inertiaTensor = Vector3.zero;
 meshRigidBody.inertiaTensorRotation = Quaternion.identity;
         
 // set the collider mesh.
 // THIS is the line that is throwing the error.
 meshCollider.sharedMesh = Instantiate(collisionMesh) as Mesh;

Yet that does absolutely nothing. How am I suppose to set the tensor manually?????????? (Note: I don't even need the physics that is going on with the tensor stuff, but we need a RigidBody)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by nullstar · Feb 20, 2013 at 10:09 AM

Have you tried setting the inertia tensor to something other than a zero vector? A zero inertia tensor only makes sense for a kinematic body which is perhaps why Unity is still attempting to calculate it from the volume anyway. You could calculate an approximate inertia tensor by imagining a bounding volume around your mesh and using one of the equations from here -> "List_of_moment_of_inertia_tensors". Note that Unity's inertia tensor vector is the diagonal elements of the matricies in the given link.

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 Fattie · Feb 20, 2013 at 10:15 AM 0
Share

exactly correct!

avatar image Fattie · Feb 20, 2013 at 10:18 AM 1
Share

Doctor .. "(Note: I don't even need the physics that is going on with the tensor stuff, but we need a RigidBody)"

Physics does not exist without the moments of inertia.

WHAT IS IT YOU ARE TRYING TO DO?

if you simply set the freezes on the rigidbody, that eli$$anonymous$$ates all such calculations.

It just depends what you're trying to do. WHY are you using a rigidbody?

There's probably an extremely easy solution. Cheers

avatar image DoctorWhy · Feb 20, 2013 at 03:39 PM 0
Share

I have tried setting the inertiaTensor to the one vector, and that didn't change anything.

Rigid bodies help with something to do with animations (I can get the exact reasons if you want). Either way, I know for a 100% fact that I need them.

The rigid bodies are kinematic, yet the error is still thrown.

I don't know what will happen if I freeze all of the transformations, but I will give that a try and get.back to you.

avatar image nullstar · Feb 20, 2013 at 04:04 PM 0
Share

From the Unity docs:

If you don't set intertia tensor from a script it will be calculated automatically from all colliders attached to the rigidbody.

Does your object start off with a rigidbody and a valid collision mesh attached in the editor? If that's the case then Unity is probably trying to calculate the inertia tensor from the attached collider during initialisation, before your script which manually sets the tensor is run. In this case you should remove the collider from your object in the editor and only add it in script after the manual setup of the tensor has occured.

avatar image DoctorWhy · Feb 21, 2013 at 04:32 PM 0
Share

Freezing the transformations did nothing. The model is in an asset bundle, but I think it might have the default mesh collider at startup. The line above is when the mesh collider is changed each and every time. But if Unity decides to test for a tensor every time because one wasn't set at a very specific moment, they need to state where. In the Awake, the mesh collider that was assigned to it (public) isn't initialized yet, so I can't set the tensor there. And setting it in the start function does nothing. Where else could I set it??

avatar image
0

Answer by Mike McFarland · Mar 13, 2013 at 06:44 PM

I had a situation where the behavior of plane colliders (only one side collides) was desired on parts of a rigid body which also had other valid colliders. What ended up being effective was disabling the collider behaviours on the prefab, then before the colliders were needed capture the already calculated tensor, cache it, enable the colliders, and then set the values afterwards.

 Vector3 planeInertiaTensor = topPlane.rigidbody.inertiaTensor;
 Quaternion planeIntertiaTensorRotation = topPlane.rigidbody.inertiaTensorRotation;
 
 foreach (MeshCollider collider in planeColliders)
 {
     try
     {
         collider.enabled = true;
     }
     catch { }
     
 }
 
 topPlane.rigidbody.inertiaTensor = planeInertiaTensor;
 topPlane.rigidbody.inertiaTensorRotation = planeIntertiaTensorRotation;

One thing to note, as soon as the colliders were enabled the error occurs, so a try / catch block was used. Not exactly an elegant solution but this worked for me. Is there a chance setting this tensor is actually working for you and you just need to deal with the exception?

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.

Follow this Question

Answers Answers and Comments

13 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

Related Questions

How do I programmatically Combine Inertia Tensors? 2 Answers

How do i create a SVM in unity using tensorflow? 0 Answers

How can I detect Actors which will cause the "Compute mesh inertia tensor failed!" error? 1 Answer

How to calculate inertia tensor and tensor rotation manually 2 Answers

Excluding a collider from tensor calculations? 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