Simple ECS/DOTS collision system not working
Hey. I am new to ECS, specially the latest package versions, and I am facing difficulties getting even a simple collision detection system to fire properly. All I want to do is detect a collision with a console message and even that seems to be beyond me. The code below compiles fine and it's an adaption of some older examples I found, using the "new" SystemBase instead of the JobComponentSystem. However, when I shoot my projectiles all over the scene and see them hit (and bounce of) my targets, no console message shows up. At this point I am little frustrated with this, so please any help or comment you could provide, would be most welcomed. Thanks in advance.
using UnityEngine;
using Unity.Jobs;
using Unity.Entities;
using Assets.ACS.Scripts.DataComponents;
using Unity.Transforms;
using Unity.Mathematics;
using Unity.Physics;
using Unity.Physics.Systems;
using Unity.Burst;
namespace Assets.ACS.Scripts.Systems
{
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
[UpdateAfter(typeof(ExportPhysicsWorld))]
[UpdateBefore(typeof(EndFramePhysicsSystem))]
public partial class ACS_CollisionSystem : SystemBase
{
BeginInitializationEntityCommandBufferSystem ecbSystem;
BuildPhysicsWorld buildPhysicsWorldSystem;
StepPhysicsWorld stepPhysicsWorldSystem;
protected override void OnCreate()
{
ecbSystem = World.GetOrCreateSystem<BeginInitializationEntityCommandBufferSystem>();
buildPhysicsWorldSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<BuildPhysicsWorld>();
stepPhysicsWorldSystem = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<StepPhysicsWorld>();
RequireForUpdate(GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[] { typeof(ACS_ProjectileData) }
}));
}
[BurstCompile]
private struct CollisionEventJob : ICollisionEventsJob
{
public void Execute(CollisionEvent collisionEvent)
{
Debug.Log("Collision");
}
}
protected override void OnStartRunning()
{
base.OnStartRunning();
this.RegisterPhysicsRuntimeSystemReadOnly();
}
protected override void OnUpdate()
{
// Schedule physics check
Dependency = new CollisionEventJob().Schedule(stepPhysicsWorldSystem.Simulation, Dependency);
}
}
}
Answer by andrew-lukasik · May 09 at 08:25 PM
Mandatory question, have you checked this setting yet?:
Ok. I feel quite stupid ... more than usual! :D It was exactly that! I was using the "ConvertToEntity" script on a GO and it was not setting that on the PhysicsShape equivalent to the good old SphereCollider. Thanks a lot for helping me out with this! It might seem stupid on retrospective, but it had me quite baffled. Again, many thanks!
It's fine. This little detail surprises even the best of us :T
Your answer
![](https://koobas.hobune.stream/wayback/20220613060345im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I need the functionality of both OnTriggerEnter and OnCollisionEnter in unity 1 Answer
How to make gridbased movement while also using collision? 0 Answers
Scheduling and dependency issues in dots. 0 Answers
Why/How 2d tower of blocks collapse? 0 Answers
OverlapBox is not detecting all objects inside it. 0 Answers