#How can I work with script with ConfigurableJoint in DOTS?

1 messages · Page 1 of 1 (latest)

sick garden
#

If I add a ConfigurableJoint to my character in the subscene, it works correctly, however I wanted to modify it during run script. I know I can use PhysicsJoint, however when I Query for PhysicsJoint, it doesn't find anything(and I'm guessing that it won't either, is that correct?)

mystic trellis
#

if you open the entity inspector and set to runtime, it should show what the baking results in. the rigidbody for each bone should be in worldspace, and parented to it should be the joint entities with the PhysicsJoint and PhysicsConstrainedBodyPair under the rigidbody

#

sorry entities hierarchy, not inspector

sick garden
mystic trellis
#

the joint doesnt appear connected to anything in your second post

sick garden
mystic trellis
#

just tried this, configurable doesnt appear to be baking for me which might be the issue

sick garden
#

Thank you for trying Baron

mystic trellis
#

change the xmotion to something other than free, does it change the baking result(think it should)?

mystic trellis
sick garden
#

Do you think it could be the Unity verison Baron?

#

I'm using 6000.0.32f1

mystic trellis
#

screenshot of entities hierarchy?

#

or select the child of that entity

#

so PhysicsJoint and the constrained component arent added to the originating entity that is the rigidbody, its another separate entity

sick garden
#

Mine seems to be missing things from yours

sick garden
mystic trellis
#

yeah set both to runtime

sick garden
#

Oh wait

#

Found it

#

So, the PhysicsJoint will be a child Entity of an Entity? @mystic trellis

mystic trellis
#

yeah

sick garden
# mystic trellis yeah

I was trying to do this Query:

    foreach ((RefRO<SyncPhysicsJointComponent> syncPhysicsJointComponent,
        RefRW<PhysicsJoint> physicsJoint)

        in SystemAPI.Query<
        RefRO<SyncPhysicsJointComponent>,
        RefRW<PhysicsJoint>>())

However the PhysicsJoint won't be in the same Entity. Do you know a way I could do this?

mystic trellis
#

just guessing but a bakingsystem to find entities with the PhysicsConstrainedBodyPair and using that you could find the rigidbody entity, and add any extra components for your runtime system to act on. I havent ever modified joint data at runtime so not familiar with the process

sick garden
#

Gonna study a bit

mystic trellis
#

good luck 🙂

sick garden
sick garden
#

I'm having no luck. If someone knows how to get the reference for the PhysicsJoint I would appreciate a lot xD

deep harness
#

show current attempt

sick garden
# deep harness show current attempt

I'm studying how to create PhysicsJoints through script, however if there is an easier way to just get the PhysicsJoints that Unity creates when I add a ConfigurableJoint, it would be easier.

#

What if I create a Tag named "SetPhysicsJointsReference", then I have a System that will constantly Query for that Tag, so when a Character is instantiated, it will search for the PhysicsJoints in the child Entity and set the reference, after is done, it will remove the Tag. Would that be efficient?

#

I think it would be easier to just create PhysicsJoint through script...

sick garden
#

So I had this idea. I added the ConfigurableJoint in some Entities, so Unity will create 2 entities as a child with PhysicsJoints, I then created a PostBaking System, and in it I put a Debug to check how many childs entities there were inside these Components, and it shows 0, even though I can clearly see them in the Entities Hierarchy, here is the code below and the images

#
using System.Diagnostics;
using Unity.Burst;
using Unity.Entities;
using Unity.Physics;
using Unity.Transforms;
using static SyncPhysicsJointAuthoring;

[WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)]
[UpdateInGroup(typeof(PostBakingSystemGroup))]
partial struct SyncPhysicsJointBakingSystem : ISystem
{

    //[BurstCompile]

    public void OnUpdate(ref SystemState state)
    {
        foreach (RefRW<SyncPhysicsJointComponent> syncJoint in SystemAPI.Query<RefRW<SyncPhysicsJointComponent>>())
        {
            Entity mainEntity = syncJoint.ValueRO.thisEntity;

            UnityEngine.Debug.Log($"Entity {mainEntity} has Child: {state.EntityManager.HasComponent<Child>(mainEntity)}");

            if (state.EntityManager.HasComponent<Child>(mainEntity))
            {

                DynamicBuffer<Child> childBuffer = state.EntityManager.GetBuffer<Child>(mainEntity);

                int jointCount = 0;
                UnityEngine.Debug.Log($"Checking entity: {mainEntity}");

            }
        }
    }
}