#using Collider->GetChild returns non-existent entity
1 messages · Page 1 of 1 (latest)
struct WheelCollisionJob : ICollisionEventsJob
{
[ReadOnly] public ComponentLookup<VehicleComponent> vehicleComponentLookup;
[ReadOnly] public ComponentLookup<PhysicsCollider> physicsColliderLookup;
[ReadOnly] public ComponentLookup<WheelComponent> wheelComponentLookup;
public void Execute(CollisionEvent collisionEvent)
{
Entity vehicleEntity = GetVehicleEntity(collisionEvent, out ColliderKey vehicleColliderKey);
if (vehicleEntity == Entity.Null) return;
Debug.Log("vehicle Entity");
if (!physicsColliderLookup.TryGetComponent(vehicleEntity, out PhysicsCollider vehiclePhysicsCollider)) return;
Debug.Log("vehicle physics collider");
Entity wheelEntity = GetWheelChildCollidedEntity(vehiclePhysicsCollider, ref vehicleColliderKey);
//stops here
if (wheelEntity == Entity.Null) return;
Debug.Log("wheel collision");
}
Entity GetWheelChildCollidedEntity(PhysicsCollider vehiclePhysicsCollider, ref ColliderKey vehicleColliderKey)
{
unsafe
{
if (!vehiclePhysicsCollider.ColliderPtr->GetChild(ref vehicleColliderKey, out ChildCollider vehicleEntityChildCollided)) return Entity.Null;
if (wheelComponentLookup.HasComponent(vehicleEntityChildCollided.Entity)) return vehicleEntityChildCollided.Entity;
return Entity.Null;
}
}
private Entity GetVehicleEntity(CollisionEvent collisionEvent, out ColliderKey vehicleColliderKey)
{
if (vehicleComponentLookup.HasComponent(collisionEvent.EntityA))
{
vehicleColliderKey = collisionEvent.ColliderKeyA;
return collisionEvent.EntityA;
}
else if (vehicleComponentLookup.HasComponent(collisionEvent.EntityB))
{
vehicleColliderKey = collisionEvent.ColliderKeyB;
return collisionEvent.EntityB;
}
vehicleColliderKey = ColliderKey.Empty;
return Entity.Null;
}
}```
entity with collider doesn't have your component
potentially your wheel is just child entity of your collider entity
inspect subscene in edit mode
and see how your component-entity relationships are setup for your wheels
are you referring to the vehicle entity or wheel entity?
whatever is relevant here
you check collider entity - it has no component
are you sure it's supposed to?
just checked my vehicle entity during runtime, the vehicle has a physics collider and vehicle component, and the wheel has a wheel component, but no physics collider? (there are physics colliders in the prefab)
the wheel is 4 stages deep in the hierchy
physics colliders can only exist at root of physics body
so they probably get moved to root
while your wheel is somehwere as a child
so does this mean unity creates a fake entity child?
I'm getting entities returned when I do GetChild that don't exist in the inspector though
it's got a collider
wheels have got a wheel component
when I debug cs if (!vehiclePhysicsCollider.ColliderPtr->GetChild(ref vehicleColliderKey, out ChildCollider vehicleEntityChildCollided)) return Entity.Null;
vehicleEntityChildCollided, it prints out an entity that doesn't exist in the inspector, any reason for this?
I was thinking of making use of the keys in the Physics Collider Key Entity Pair buffer (on the root entity), might lead me somewhere
yep, looks like the collider keys in the root entity buffer match the ones in the collision event, will cache those and use them to find the correct entity