Search Unity

[0.2.5.preview.1 + NetCode] Build Physics World Does Not Pick Up PhysicsVelocity Component

Discussion in 'Physics for ECS' started by florianhanke, Jan 14, 2020.

  1. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    tl;dr Entity with PhysicsVelocity+Translation+Rotation components is not picked up by BuildPhysicsWorld#
    DynamicEntityGroup query.

    This issue occurs in 0.2.5.preview.1 in the Server World (NetCode), but to my knowledge did not occur in earlier versions. I believe it also did occur outside NetCode.

    I have a weird issue where the `DynamicEntityGroup` in `BuildPhysicsWorld` is empty because I have no `PhysicsVelocity` components, even though I have GOs in the scene which have a `Physics Body` authoring component with Motion Type `dynamic`.

    This then results in a failure in the CreateJoints method, because `[CreateJoints] pair.BodyAIndex: -1, pair.BodyBIndex: -1`.

    As usual, the issue occurs in my example car (are you sick of it already? :D:(), where I have four wheels which are connected to the main car body via joints, and they are in a parent-child relationship with the main body. Each wheel has a `Physics Body` authoring component.

    Screenshot 2020-01-14 at 16.12.50.png

    When I start paused play mode, after clicking step once, the `BuildPhysicsWorld` system appears, but finds 0 dynamic bodies, since none of the wheels appear to have a `PhysicsVelocity` (or Translation or Rotation) component, according to the `BuildPhysicsWorld` system.

    When I add a cube to the scene with a `Physics Body`authoring component with Motion Type `dynamic` it receives a `PhysicsVelocity` component normally.

    So, with the cube, in the debugger, I have this situation:

    Screenshot 2020-01-14 at 16.44.24.png

    Only the Cube is picked up in the BPW system as dynamic, but none of the wheels.

    In the console, I am printing some information about what happens in the BPW system:

    Screenshot 2020-01-14 at 16.44.42.png

    So it picks up the one dynamic body (the Cube), and then tries to find bodies for the joints, which it fails, because the only bodies are the Cube and the plane, but none of the wheels.

    However, in the debugger, when I select a wheel (entity 24), it lists that it has all the needed components to be picked up by the BPW system as a dynamic body:

    Screenshot 2020-01-14 at 16.45.22.png

    I am utterly confused – why would entity 24 with PhysicsVelocity+Translation+Rotation components not be picked up by BuildPhysicsWorld?

    I am happy to try and compile a case, but wanted to first ask if this is a known issue and if perhaps there is an obvious mistake I am making...? (Especially since the debugger clearly shows entity 24 with the necessary components)

    Cheers and thanks for any help!
     
    Last edited: Jan 15, 2020
  2. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    An update:

    I noticed that the entity debugger had somehow cached All Entities – after reclicking it, the wheels disappeared and I only saw:

    Screenshot 2020-01-14 at 17.26.07.png

    This is the initial state – for some reason, the `PhysicsJoint`s are already listed, but the wheels and the main car body are not.

    Roughly 10 steps later, the wheels appear, but they do not have the original entity ID, so of course, the BuildPhysicsWorld system falls on its nose when trying to CreateJoints, since the joints still have the old entity IDs. For example, the joint with entity id 33 points to entity id 24 and entity id 5, which once were wheels, but now the wheels occupy ids 58 to 61.

    Screenshot 2020-01-14 at 17.28.46.png

    I'm starting to think it may be connected to NetCode and that perhaps I may not be using these two correctly in combination. But even so, the fact that the joints at one point exist on their own is very curious…?
     
  3. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    Sorry for the probably confused seeming post. I believe now that the Entity Debugger was giving me erroneous information, in addition to the issue that I am actually having. This weird combination did not help :D

    Posted a bug report on the Entity Debugger feedback thread here: https://forum.unity.com/threads/entity-debugger-feedback.522893/page-4#post-5372754 Pretty unsure if anyone still reads it…?

    I hope I can try to isolate the above issue where physics bodies for joints are not found anymore in a bug report.
     
  4. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    I've tried isolating the issue, and potentially found another issue: https://forum.unity.com/threads/cas...r-cube-processed-in-buildphysicsworld.809796/

    Also, I noticed that the Joints are not from Unity Physics, but it is code taken from a Physics team member – sorry about that, I forgot. This may explain why they behave differently to the other Physics components (they are in the world, while the other physics component entities are not). I'll try to figure out why they are treated differently.