Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Confusing "Fit To Enabled Render Meshes" Behaviour

Discussion in 'Physics for ECS' started by florianhanke, Dec 15, 2019.

  1. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    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).

    Screenshot 2019-12-15 20.12.05.png

    This is the axle's
    PhysicsShape
    component:

    Screenshot 2019-12-15 20.12.15.png

    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.

    Screenshot 2019-12-15 20.12.21.png

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

    Happy for any pointers, thanks in advance!
     
  2. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    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.
     
  3. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    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!
     
    Adam-Mechtley likes this.