Greetings faced with such a problem. I need to get a list of all entities trapped in the cube collider, for this I decided to use the BoxCastAll function, but it gives the error UNKOWN_TYPE_OBJECT can anyone suggest ways to get all the objects trapped in the cube grid?
do those entities have collider ? if have, just just colliderEvent
There is a Physics Shape, how do I call ColliderEvent when two objects intersect? I’ve tried using this code, but it only works when there is a Physics Body on the objects, which I can’t use.
using Unity.Burst;
using Unity.Entities;
using Unity.Jobs;
using Unity.Physics;
using Unity.Physics.Systems;
using UnityEngine;
[UpdateAfter(typeof(EndFramePhysicsSystem))]
public class CollisionECS : JobComponentSystem
{
private BuildPhysicsWorld buildPhysicsWorldSystem;
private StepPhysicsWorld stepPhysicsWorldSystem;
private EndSimulationEntityCommandBufferSystem commandBufferSystem;
protected override void OnCreate()
{
buildPhysicsWorldSystem = World.GetExistingSystem<BuildPhysicsWorld>();
stepPhysicsWorldSystem = World.GetExistingSystem<StepPhysicsWorld>();
commandBufferSystem = World.GetExistingSystem<EndSimulationEntityCommandBufferSystem>();
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var collision = new CollisionJob()
{
fragment = GetComponentDataFromEntity<FragmentECS>(),
cutter = GetComponentDataFromEntity<CutterECS>(),
};
JobHandle jobHandle = collision.Schedule(
stepPhysicsWorldSystem.Simulation,
ref buildPhysicsWorldSystem.PhysicsWorld,
inputDeps);
commandBufferSystem.AddJobHandleForProducer(jobHandle);
return jobHandle;
}
[BurstCompile]
private struct CollisionJob : ICollisionEventsJob
{
public ComponentDataFromEntity<CutterECS> cutter;
public ComponentDataFromEntity<FragmentECS> fragment;
public void Execute(CollisionEvent collisionEvent)
{
if (cutter.HasComponent(collisionEvent.EntityB))
{
if (fragment.HasComponent(collisionEvent.EntityA))
{
Debug.Log("BOOM");
}
}
}
}
}
OK, I did it, it turns out it was necessary to put an event call on the objects, thanks for the tip!