I have a trigger attached to enemies in my project.
I am adding DamageZoneComponent to decorate the trigger collision box.
Next in a system I am trying to find all DamageZoneComponent decorated entities that are colliding with player.
When I use ComponentLookup to check if an entity has DamageZoneComponent non of them turn out to have it.
This is impossible as I am decorating all DamageZones with it. There are no other trigger colliders in the scene. I do get
triggerEvent.EntityB to have PlayerComponent but no DamageZoneComponents attached to triggerEvent.EntityA.
Any tips what I might be doing wrong is appreciated, otherwise it looks like a bug to me.
Attaching the whole system code as I might have some setup wrong.
```csharp
**using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Physics;
using Unity.Physics.Systems;
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
[UpdateAfter(typeof(PhysicsSystemGroup))]
[BurstCompile]
public partial struct DamageZoneCollisionSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state) { }
[BurstCompile]
public void OnDestroy(ref SystemState state) { }
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var simuilationSingleton = SystemAPI.GetSingleton<SimulationSingleton>();
var playerEntity = SystemAPI.GetSingletonEntity<PlayerComponent>();
var player = SystemAPI.GetAspectRW<PlayerAspect>(playerEntity);
var damageZonesCollidingWithPlayer = new NativeList<Entity>(Allocator.TempJob);
state.Dependency = new CheckDamageZoneCollisionWithPlayer()
{
DamageZonesCollidingWithPlayer = damageZonesCollidingWithPlayer,
DamageZoneLookup = SystemAPI.GetComponentLookup<DamageZoneComponent>(isReadOnly: true),
PlayerLookup = SystemAPI.GetComponentLookup<PlayerComponent>(isReadOnly: true),
}
.Schedule(simuilationSingleton, state.Dependency);
state.Dependency.Complete();
foreach (var (damageZone, damageZoneEntity) in SystemAPI.Query<RefRW<DamageZoneComponent>>().WithEntityAccess())
{
if (damageZonesCollidingWithPlayer.Contains(damageZoneEntity))
{
damageZone.ValueRW.Countdown -= SystemAPI.Time.DeltaTime;
if (damageZone.ValueRW.Countdown < 0)
{
player.Life -= damageZone.ValueRO.Damage;
damageZone.ValueRW.Countdown = damageZone.ValueRO.Time;
}
}
else
{
damageZone.ValueRW.Countdown = -1f;
}
}
damageZonesCollidingWithPlayer.Dispose();
}
[BurstCompile]
struct CheckDamageZoneCollisionWithPlayer : ITriggerEventsJob
{
public NativeList<Entity> DamageZonesCollidingWithPlayer;
[ReadOnly] internal ComponentLookup<DamageZoneComponent> DamageZoneLookup;
[ReadOnly] internal ComponentLookup<PlayerComponent> PlayerLookup;
[BurstCompile]
public void Execute(TriggerEvent triggerEvent)
{
if (DamageZoneLookup.HasComponent(triggerEvent.EntityA))
{
UnityEngine.Debug.Log("EntityA is damage zone");
}
if (DamageZoneLookup.HasComponent(triggerEvent.EntityB))
{
UnityEngine.Debug.Log("EntityB is damage zone");
}
if (PlayerLookup.HasComponent(triggerEvent.EntityA))
{
UnityEngine.Debug.Log("EntityA is player");
}
if (PlayerLookup.HasComponent(triggerEvent.EntityB))
{
UnityEngine.Debug.Log("EntityB is player");
}
// if (PlayerLookup.HasComponent(triggerEvent.EntityA) && DamageZoneLookup.HasComponent(triggerEvent.EntityB))
// {
// DamageZonesCollidingWithPlayer.Add(triggerEvent.EntityB);
// }
// if (PlayerLookup.HasComponent(triggerEvent.EntityB) && DamageZoneLookup.HasComponent(triggerEvent.EntityA))
// {
// DamageZonesCollidingWithPlayer.Add(triggerEvent.EntityA);
// }
}
}
}**
```