Hello, I’m having trouble getting trigger events between 2 entities and I could use a reality check. Here’s my job and the authoring for both prefabs:
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Physics;
using Unity.Physics.Systems;
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
[UpdateAfter(typeof(StepPhysicsWorld))]
[UpdateBefore(typeof(EndFramePhysicsSystem))]
public partial class ApplyOnHitEffectJobSystem : SystemBase
{
private StepPhysicsWorld m_StepPhysicsWorld;
protected override void OnCreate()
{
m_StepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
RequireForUpdate(GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[] { typeof(ApplyOnHitEffect) }
}));
}
protected override void OnStartRunning()
{
this.RegisterPhysicsRuntimeSystemReadOnly();
}
protected override void OnUpdate()
{
//Dependency.Complete();
var applyOnHitEffectJob = new ApplyOnHitEffectJob
{
commandBuffer = World.GetExistingSystem<EndSimulationEntityCommandBufferSystem>().CreateCommandBuffer(),
applyOnHitEffectFromEntity = GetComponentDataFromEntity<ApplyOnHitEffect>(true),
applyAbilityEffectFromEntity = GetBufferFromEntity<ApplyAbilityEffect>(true),
casterFromEntity = GetComponentDataFromEntity<Caster>(true),
}.Schedule(m_StepPhysicsWorld.Simulation, Dependency);
Dependency = applyOnHitEffectJob;
//applyOnHitEffectJob.Complete();
}
[BurstCompile]
public struct ApplyOnHitEffectJob : ITriggerEventsJob
{
public EntityCommandBuffer commandBuffer;
[ReadOnly] public ComponentDataFromEntity<ApplyOnHitEffect> applyOnHitEffectFromEntity;
[ReadOnly] public BufferFromEntity<ApplyAbilityEffect> applyAbilityEffectFromEntity;
[ReadOnly] public ComponentDataFromEntity<Caster> casterFromEntity;
public void Execute(TriggerEvent triggerEvent)
{
// Initialize necessary variables to apply effects
var effectEntity = Entity.Null;
var caster = Entity.Null;
var target = Entity.Null;
if (applyOnHitEffectFromEntity.HasComponent(triggerEvent.EntityA))
{
effectEntity = applyOnHitEffectFromEntity[triggerEvent.EntityA].effect;
}
if (applyOnHitEffectFromEntity.HasComponent(triggerEvent.EntityB))
{
effectEntity = applyOnHitEffectFromEntity[triggerEvent.EntityB].effect;
}
if (casterFromEntity.HasComponent(triggerEvent.EntityA))
{
caster = casterFromEntity[triggerEvent.EntityA].caster;
}
if (casterFromEntity.HasComponent(triggerEvent.EntityB))
{
caster = casterFromEntity[triggerEvent.EntityB].caster;
}
if (applyAbilityEffectFromEntity.HasComponent(triggerEvent.EntityA))
{
target = triggerEvent.EntityA;
}
if (applyAbilityEffectFromEntity.HasComponent(triggerEvent.EntityB))
{
target = triggerEvent.EntityB;
}
// If the values are not set, exit early.
if (effectEntity == Entity.Null ||
caster == Entity.Null ||
target == Entity.Null)
{
return;
}
// Apply the effect
var effectInstance = commandBuffer.Instantiate(effectEntity);
commandBuffer.AddComponent(effectInstance, new Caster { caster = caster });
commandBuffer.AppendToBuffer(target, new ApplyAbilityEffect { effect = effectInstance });
}
}
}
The ability authoring and its “Collides With” categories:
The enemy (no categories since it’s “Everything”):
1st of all: The ability entity definitely has the ApplyOnHitEffect and Caster component and the enemies definitely have ApplyAbilityEffect buffers… so what am I doing wrong? In the attached gif I am expecting them to die (be destroyed) but they aren’t. This has to be a collision filter issue but I just don’t understand how.