Search Unity

Bug LimitedHinge joint entity created twice

Discussion in 'DOTS Physics' started by hauwing, Feb 19, 2021.

  1. hauwing

    hauwing

    Joined:
    Dec 13, 2017
    Posts:
    61
    Hi,

    If a Gameobject (physic body) is added with both a LimitedHinge joint and a ball and socket joint connecting to another gameobject (physic body), the LimitedHinge entity will be created twice. This can be reproduced by using the Unity Physic Demo - 4a. Joints Parade. If a ballandsocket joint is added to the lower box, the original LimitedHinge joint will be created twice.

    upload_2021-2-19_13-35-32.png

    upload_2021-2-19_13-35-3.png
     
  2. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    Hi @hauwing , thank you for reporting this! It's a bug in our PhysicsJointConversionSystem and it will be fixed asap. Not sure when the fix will be released, but if you need it urgently please let me know and I'll post the code that needs to be changed.
     
  3. hauwing

    hauwing

    Joined:
    Dec 13, 2017
    Posts:
    61
    Thanks, not super urgent but it would be great if you can post the code here. thx.
     
  4. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    Sure! Just change Assets/Demos/4. Joints/Scripts/Conversion/PhysicsJointConversionSystem.cs to have these (add CreateJoints<T>, change OnUpdate):
    Code (CSharp):
    1. protected void CreateJoints<T>() where T : BaseJoint
    2.         {
    3.             Entities.ForEach((T joint) =>
    4.             {
    5.                 foreach (var j in joint.GetComponents<T>())
    6.                 {
    7.                     if (joint.GetType() == j.GetType())
    8.                     {
    9.                         CreateJoint(j);
    10.                     }
    11.                 }
    12.             });
    13.         }
    14.  
    15.         protected override void OnUpdate()
    16.         {
    17.             CreateJoints<BallAndSocketJoint>();
    18.             CreateJoints<FreeHingeJoint>();
    19.             CreateJoints<LimitedHingeJoint>();
    20.             CreateJoints<LimitedDistanceJoint>();
    21.             CreateJoints<PrismaticJoint>();
    22.             CreateJoints<RagdollJoint>(); // Note: RagdollJoint.Create adds 2 entities
    23.             CreateJoints<RigidJoint>();
    24.             CreateJoints<LimitDOFJoint>();
    25.         }
     
    steveeHavok and Sab_Rango like this.
unityunity