GetCenterOfMass returns zeros

We are attempting to use GetCenterOfMass for static mesh objects as shown here:

GetCenterOfMass returns zeroes until we temporarily check on and off “Simulate Physics”, i.e. “Simulate” is OFF for all objects:

Now the result is correct:

I am confused why I get valid COM for some objects, and zeros for others - with “Simulate” disabled for all objects, and as far as I can see in “Details” panel, their settings are identical.

Please help - we are refining FBX import pipeline for industrial parts, and interim solution of temporarily checking “Simulate Physics” seems bit round-about … Perhaps I am missing some basic concept here?

Tested on UE4.8.3 and 4.9.0Preview4

Thanks!!!

An object doesn’t have a COM if it is not simulating physics , why you need exactly the COM

It’s intended behavior as it is even described in function description:

Following the source code, this function grab center of the mass directly from physics engine, so if it’s offline for that object it can’t get it.

Hi ! thanks for your answer, but I am still confused…

If “Simulate Physics” setting enables Center Of Mass computation - then why turning it OFF again in “Details” panel still returns valid coordinates - what has changed, as I am getting valid coordinates with “Simulate Physics” turned off?

In other words, is there a better way of enabling Center Of Mass for imported static meshes other than clicking “Simulate Physics” ON and then OFF again for each?

Hi Mhousse1247! thanks for your answer, but I am still confused…

If “Simulate Physics” setting enables COM computation - then why turning it OFF again in “Details” panel still returns valid result?

In other words, is there a better way of enabling Center Of Mass for imported static meshes other than clicking “Simulate Physics” ON and then OFF again for each object?

Hi ,

Mhousse1247 & are correct. The CoM of an object is not calculated until simulate physics is enabled. Once it is, those values are ‘saved’. Which is why the values remain even after physics is disabled.

I hope that helps clarify a bit.

Cheers,

TJ

I think you are for the pivot point of a SM , you can get that by GetWorlLocation

Thanks, TJ, that makes sense.

I would like to program a more elegant solution for COM, perhaps something like Simulate=ON to allow COM calculation but setting rigid parameters to prevent motion… or doing the calculation directly …

Thanks for your reply.

Thanks, Mhousse1247. Unfortunately GetWorldLocation (or GetActorLocation for static mesh actor) can’t work, because our FBX import pipeline takes large batch of meshes and sets their pivots at the same spatial coordinate for easy fit/alignment of components into larger parts; From TJ’s comments (below) it appears that temporarily enabling “Simulate” pre-computes COM, still available to GetCenterOfMass even after “Simulate” is turned off… Quick and dirty but works for now!

I would like to find more elegant solution, perhaps something like Simulate=ON to allow COM calculation but setting rigid parameters to prevent motion… or doing the calculation directly … I am open to suggestion if there is an easy way in Unreal here to get SM’s physical location.

Thanks for fast response!!!

I don’t know if this can help but there is also “Get Component Bounds” or “Get Actor Bounds” it return the centre and the extent of one or a group of PrimitiveComponents

Thanks to Mhousse1247, GetComponentBounds works independent of “Simulate” settings.

I experimented a bit, and found that setting static mesh to “movable” results in correct computation of CenterOfMass without having to enable “Simulate Physics” … but GetComponentBounds (or GetActorBounds) is cleanest!

Again, thanks for awesome hands-on response, Mhousse1247, you rule!!!