I have clearly missed something
Place a sphere above a capsule on an empty scene
add to both the following, convert to entity, physics body, physics shape and set raises collision events on the physics shape
in the capsule set gravity to 0
If you now hit play your ball should fall and hit the capsule. great.
I then made a system of
public class MyCollisionSystem : ICollisionEventsJob
{
public void Execute(CollisionEvent collisionEvent)
{
Debug.Log($"Collision between {collisionEvent.Entities.EntityA} and {collisionEvent.Entities.EntityB}");
}
}
But the debug.log never seems called - so, what in the name of thats codey have I missed? The capsule then falls off screen because the ball has pushed it, so, it made contact… why does this code not happen…
Edit, how would I then access component data (if i put it on of course) on those entities to say decrement HP from a data struct of
[GenerateAuthoringComponent]
public struct HealthData : IComponentData
{
public int hp;
}
You seemed to have confused the terms system and job. You have created (incorrectly as a class) a job that still needs to be scheduled. Note, I have not used the physics aspect of the ECS yet; however, assuming you schedule your job the entities in the parameter could be used in the GetComponentData (unsure of the name as it has changed a few times) that is passed in via field to the job struct.
Well. I’m even more confused now. Ok so it’s a job but the class is derived from and adheres to the collision provided. The only parameters were those listed. So
then I’m still missing something and I don’t see what
Thanks @Divide , for some reason Ive seen that thread and looked at it a bunch, but something is still clearly not sinking in right. Unity have given us an ICollisionEventJob, and the link you has shows a collision but not between what and what, nor, am I getting how I can take an entity and find components on it, and say “remove some health” … Plus, thats a heck of a lot of code to say “Ow he hit me”
of course it also doesnt help that the whole dots thing has been changing while we are trying to work with it, so some examples are more old original ecs, and some are more new ecs styles…
Yep it’s a lot of code. I also found this posted yesterday kinda similar but for triggers instead of collisions, but I think comparing the two might help things make sense.
I’m on holiday so best I can do is just read stuff but cant wait to play around with all the new stuff when I’m home
Thanks again @Divide (hope you have a nice hols) meh if I can make it work as a trigger, I can still work with that… Ideally I want to understand why and how they got to what they did, so I learn rather than just copy mind.
I like and love the concept of dots, but of course like a lot of things its a long way from how Ive been bought up on unity and occasionally my brain farts and just says “nope” … and this maybe one of those things… Clearly any project with many items would benefit from dots, I just hope they come up with a dots happy navmesh, and all the other gizmos…