Hi, I’m exploring DOTS and doing else perfectly working tutorial and got stuck no this code with triggering collisions. Code, as you see below, throws warning: "
“Ignoring invalid [UpdateAfter] attribute on Systems.PickupOnTriggerSystem targeting Unity.Physics.Systems.EndFramePhysicsSystem.
This attribute can only order systems that are members of the same ComponentSystemGroup instance.
Make sure that both systems are in the same system group with [UpdateInGroup(typeof(Unity.Entities.SimulationSystemGroup)],
or by manually adding both systems to the same group’s update list.”
That I fixed with attribute above PickupOnTriggerSystem : [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
So I get no warning, but Execute of the job is not triggered.
Also tried to add [UpdateAfter(typeof(StepPhysicsWorld))] attribute, but that do not seems to help either.
I need help with this, if anyone could, please.
using Tags;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Physics;
using Unity.Physics.Systems;
namespace Systems
{
// [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
// [UpdateAfter(typeof(StepPhysicsWorld))]
[UpdateAfter(typeof(EndFramePhysicsSystem))]
public class PickupOnTriggerSystem : JobComponentSystem
{
private BuildPhysicsWorld buildPhysicsWorld;
private StepPhysicsWorld stepPhysicsWorld;
private EndSimulationEntityCommandBufferSystem commandBufferSystem;
protected override void OnCreate()
{
base.OnCreate();
buildPhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
stepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
commandBufferSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
}
[BurstCompile]
struct PickupOnTriggerSystemJob : ITriggerEventsJob
{
[ReadOnly] public PhysicsWorld World;
[ReadOnly] public ComponentDataFromEntity<PickupTag> allPickups;
[ReadOnly] public ComponentDataFromEntity<PlayerTag> allPlayers;
public EntityCommandBuffer entityCommandBuffer;
public void Execute(TriggerEvent triggerEvent)
{
Entity entityA = triggerEvent.EntityA;
Entity entityB = triggerEvent.EntityB;
if (allPickups.HasComponent(entityA) && allPickups.HasComponent(entityB))
{
return;
}
if (allPickups.HasComponent(entityA) && allPlayers.HasComponent(entityB))
{
UnityEngine.Debug.Log($"Pickup Entity A: {entityA} collided with Player Entity B: {entityB}");
entityCommandBuffer.DestroyEntity(entityA);
}
else if (allPlayers.HasComponent(entityA) && allPickups.HasComponent(entityB))
{
UnityEngine.Debug.Log($"Player Entity A: {entityA} collided with PickUp Entity B: {entityB}");
entityCommandBuffer.DestroyEntity(entityB);
};
}
}
protected override JobHandle OnUpdate(JobHandle inputDependencies)
{
var job = new PickupOnTriggerSystemJob
{
allPickups = GetComponentDataFromEntity<PickupTag>(true),
allPlayers = GetComponentDataFromEntity<PlayerTag>(true),
entityCommandBuffer = commandBufferSystem.CreateCommandBuffer(),
};
JobHandle jobHandle = job.Schedule(stepPhysicsWorld.Simulation, ref buildPhysicsWorld.PhysicsWorld,
inputDependencies);
commandBufferSystem.AddJobHandleForProducer(jobHandle);
jobHandle.Complete();
return jobHandle;
}
}
}
