Confusing "Fit To Enabled Render Meshes" Behaviour

Hi all,

I have noticed a behaviour that I found confusing and am wondering whether it’s working as intended.

I have an AssetPostprocessor implementing class which at some point calls physicsShape.FitToEnabledRenderMeshes(); on a PhysicsShape of an axle which is the parent of two wheels.

This causes the box PhysicsShape to encompass also the child wheels (see image).

This is the axle’s PhysicsShape component:

But when I click and apply “Fit To Enabled Render Meshes” in the component editor above, the PhysicsShape axle is correctly fit to the axle.

To me, this seems inconsistent, but maybe it’s somehow intended to work this way…?

Happy for any pointers, thanks in advance!

Hi! Out of curiosity, are you adding PhysicsShapeAuthoring components to the wheels in your AssetPostprocess? (i.e. are such components on the wheels when you click it in the Inspector?)

This needs to be documented on our part, but basically the way the method works is it will fit to all the meshes in the hierarchy that do not have a PhysicsShapeAuthoring component on some interceding ancestor. So if you are fitting before these components are added to the wheels, it thinks it should fit to the axel’s entire hierarchy of meshes. The correct usage is to add all of the PhysicsShapeAuthoring components, and then have them all fit to meshes.

Hi Adam!

I am, but since the axle is an ancestor of the wheels, and iirc the AssetPostprocess processes top-down, the moment when I call the mesh fit method, the axle’s children do not have the PhysicsShapeAuthoring component yet. So after all have received their PhysicsShapeAuthoring, I’m going to have to do a second step where I call the fit method for all PhysicsShapeAuthoring component GOs.

“it will fit to all the meshes in the hierarchy that do not have a PhysicsShapeAuthoring component on some interceding ancestor” ← this especially was very helpful, many thanks!

1 Like