Author Topic: NGUI 3.0.6 - inertia tensor failed  (Read 12667 times)

mathiassoeholm

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 35
    • View Profile
NGUI 3.0.6 - inertia tensor failed
« on: November 26, 2013, 09:22:06 AM »
Hi there  :)

Since I updated to NGUI 3.0.6 I kept getting an error that has to do with rigidbodies:

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.Transform:set_parent(Transform)
NGUITools:AddChild(GameObject, GameObject) (at Assets/NGUI/Scripts/Internal/NGUITools.cs:407)

The error didn't seem to cause any trouble, but I found it very weird since I'm not using any rigidbodies.
The changelog mentions that NGUI now adds rigidbodies to the panels, perhaps this is the source of the error?

"- FIX: Panels will now add rigidbodies to themselves since Unity 4.3 mentions it should improve performance."

Thanks in advance!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0.6 - inertia tensor failed
« Reply #1 on: November 26, 2013, 11:16:05 AM »
Panels have rigidbodies now, yes -- but how are you getting to that error? Anything in particular you're doing? NGUI doesn't use any actors, or does anything with rigidbodies other than just creating and leaving them in a kinematic state.

mathiassoeholm

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 35
    • View Profile
Re: NGUI 3.0.6 - inertia tensor failed
« Reply #2 on: November 27, 2013, 03:15:03 AM »
All I am doing is loading a prefab from resources, I'm then using NGUITools.AddChild to add it to a gameobject in the scene.

  1. GameObject prefab = ResourceUtil.LoadResource<GameObject>(resourceName, ResourceUtil.ResourceType.Module);
  2. GameObject go = NGUITools.AddChild(gameObject, prefab);
  3.  

In this snippet from NGUITools.AddChild, I get the error six times from a single call to the method.

  1. if (go != null && parent != null)
  2. {
  3.         Transform t = go.transform;
  4.         t.parent = parent.transform;
  5.         t.localPosition = Vector3.zero;
  6.         t.localRotation = Quaternion.identity;
  7.         t.localScale = Vector3.one;
  8.         go.layer = parent.layer;
  9. }
  10.  

Twice on line 4 "UnityEngine.Transform:set_parent(Transform)"
Once on line 5 "UnityEngine.Transform:set_localPosition(Vector3)"
Once on line 6 "UnityEngine.Transform:set_localRotation(Quaternion)"
Twice on line 7 "UnityEngine.Transform:set_localScale(Vector3)"

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0.6 - inertia tensor failed
« Reply #3 on: November 27, 2013, 03:33:51 AM »
Is your UI a child of some moving object? Ie: is your UI stationary as it's supposed to be, or is it parented to something?

Rigidbodies are added to panels on line 520 of UIPanel. You can comment out that entire section if it's causing issues for you, but keeping rigidbodies is meant to improve performance.

mathiassoeholm

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 35
    • View Profile
Re: NGUI 3.0.6 - inertia tensor failed
« Reply #4 on: November 27, 2013, 04:39:28 AM »
Yeah, my UI is stationary.
Removing the code that adds the rigidbody did the job, but I don't like having to keep it that way.
It'll just break again with the next update then.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0.6 - inertia tensor failed
« Reply #5 on: November 27, 2013, 05:25:44 AM »
I'm curious why I haven't seen that. Can you get it to happen in any of the examples or let me know what's different about your UI setup?

Doing a quick search on google comes up with: http://answers.unity3d.com/questions/7841/what-does-the-compute-mesh-inertia-tensor-failed-e.html

..which talks about planes. Maybe it doesn't like box colliders with Z size of 0? You could change that in NGUITools.cs line 315 (UpdateWidgetCollider function):
  1. box.size = new Vector3(b.size.x, b.size.y, 1f);
as well as adding
  1. size.z = 1f;
to the 'if' statement right above it.

...but regardless I'd be nice to be able to reproduce it on my end.

mathiassoeholm

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 35
    • View Profile
Re: NGUI 3.0.6 - inertia tensor failed
« Reply #6 on: November 27, 2013, 06:21:42 AM »
That didn't seem to change anything.
I'll see if I can find a way to reproduce the error.

mathiassoeholm

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 35
    • View Profile
Re: NGUI 3.0.6 - inertia tensor failed
« Reply #7 on: November 27, 2013, 06:36:03 AM »
I finally found the source of the problem!

I had a quad under the UI with a mesh collider on it.
Replacing the mesh collider with a box collider fixed the problem.

I thought I had already replaced that collider to be honest.

Thanks for the help!

DrLoomis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Re: NGUI 3.0.6 - inertia tensor failed
« Reply #8 on: January 24, 2014, 08:40:30 PM »
I just updated my UI from 2.7.0 to 3.0.9, and when I ran the game I was getting an exceptional number of the "updateMassFromShapes: Compute mesh" errors. I got about 450 on start, and would keep getting them every few seconds as I played.

I was baffled, as my UI doesn't contain any quads or other objects that would throw this error.

Finally, after much pulling of hair, I found that NGUI had added a rigidbody to my UI's parent object for some reason. The way my project is structured, there's a parent object for everything in my scene (done for additive loading purposes), so there was a Rigidbody component on the parent of every object in my scene (player, gameplay objects, set dressing ... everything). It was causing errors to be thrown about all sorts of objects that had nothing to do with the UI.

So anyway, if you run into this error, check NGUI's parent object. As soon as I removed the incorrectly-added Rigidbody and UIPanel script (no idea on earth why that was added automatically as well) and saved my scene, everything went back to normal again.

sarkahn

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 3
    • View Profile
Re: NGUI 3.0.6 - inertia tensor failed
« Reply #9 on: March 28, 2014, 11:15:23 PM »
Just encountered this error as well. For the benefit of future googlers: This seems to be an issue with rigidbodies and mesh colliders. To reproduce it: Create a uiroot, create a box and add a mesh collider to it. Add the box to the root and reset the box's scale to 1. You will get this error. In fact the parent object doesn't actually need to be a uiroot, you can do it with an empty game object with a super small scale.

According to this: http://answers.unity3d.com/questions/14497/actorupdatemassfromshape-error.html it seems that when an object with a mesh collider and a rigidbody (or a combination of a  child object with the mesh collider and a parent object with a rigidbody in this case) is scaled too small it will start throwing out this error since the mesh collider becomes so small that it is eventually perceived as a plane. Rigidbodies don't like planes and therefore you get your error.

This is of course not an error specific to NGUI in any way, it just so happens that the uiroot is scaled incredibly small and also has a rigidbody, so if objects are added to it they become extremely tiny when their scale is reset, and if they happen to have a mesh collider then it's bad news bears.

The only "fix" is to remove the rigidbody code from UIPanel.cs as suggested or to ensure that either any added object's mesh colliders are convex or the added object's scale is never reduced to the point where the error occurs.

mikey555

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: NGUI 3.0.6 - inertia tensor failed
« Reply #10 on: October 10, 2014, 06:18:04 PM »
I've been having a similar problem. I've been trying the fix mentioned in the above post by commenting out the part of UIPanel.cs that adds a rigidbody. I commented out the if clause at line 912, but the problem still exists. I would appreciate some help, because I'm not quite advanced enough yet to go under the hood!

Is there an alternative to meshes for making complex, non-shape colliders?