I have been working on a conveyer system similar to facotrio. but I cant seem to get collision to work.
if there are any better ways to handle conveyer systems please let me know.
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using Unity.Physics;
using Unity.Physics.Systems;
public partial class RETRY : ComponentSystem
{
private BuildPhysicsWorld buildPhysicsWorld;
private StepPhysicsWorld stepPhysicsWorld;
private EndSimulationEntityCommandBufferSystem ecb;
protected override void OnCreate()
{
base.OnCreate();
buildPhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
stepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
ecb = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
}
//[BurstCompatible]
struct ConveyerSystemJob : ICollisionEventsJob
{
[ReadOnly] public ComponentDataFromEntity<ItemComponent1> AllItems;
public ComponentDataFromEntity<ConveyerComponent> allConveyers;
[ReadOnly] public ComponentDataFromEntity<ConveyerTag> allTaggedConveyers;
[ReadOnly] public ComponentDataFromEntity<LocalToWorld> World;
public EntityCommandBuffer ecb;
public void Execute(CollisionEvent collisonEvent)
{
Entity entityA = collisonEvent.EntityA;
Entity entityB = collisonEvent.EntityB;
if (allTaggedConveyers.HasComponent(entityA) && allTaggedConveyers.HasComponent(entityB))
{
return;
}
if (AllItems.HasComponent(entityA) && allTaggedConveyers.HasComponent(entityB))
{
ConveyerComponent conveyerComp = allConveyers[entityB];
if (conveyerComp.next != Entity.Null)
return;
conveyerComp.next = entityA;
LocalToWorld LWorld = World[entityB];
ecb.AddComponent(entityA, new ItemConveyerComponent());
ItemConveyerComponent New = new ItemConveyerComponent();
New.distance = 1;
New.direction = LWorld.Forward;
ecb.SetComponent(entityA, New);
allConveyers[entityB] = conveyerComp;
}
else if (AllItems.HasComponent(entityB) && allTaggedConveyers.HasComponent(entityA))
{
ConveyerComponent conveyerComp = allConveyers[entityA];
if (conveyerComp.next != Entity.Null)
return;
conveyerComp.next = entityB;
LocalToWorld LWorld = World[entityA];
ecb.AddComponent(entityB, new ItemConveyerComponent());
ItemConveyerComponent New = new ItemConveyerComponent();
New.distance = 1;
New.direction = LWorld.Forward;
ecb.SetComponent(entityB, New);
allConveyers[entityA] = conveyerComp;
}
}
}
protected JobHandle OnUpdate(JobHandle inputDeps)
{
var job = new ConveyerSystemJob();
job.AllItems = GetComponentDataFromEntity<ItemComponent1>(false);
job.allConveyers = GetComponentDataFromEntity<ConveyerComponent>(false);
job.World = GetComponentDataFromEntity<LocalToWorld>(true);
job.allTaggedConveyers = GetComponentDataFromEntity<ConveyerTag>(true);
job.ecb = ecb.CreateCommandBuffer();
JobHandle jobHandle = job.Schedule(stepPhysicsWorld.Simulation, inputDeps);
//jobHandle.Complete();
ecb.AddJobHandleForProducer(jobHandle);
return jobHandle;
}
protected override void OnUpdate()
{
throw new System.NotImplementedException();
}
}
that’s the code:::
I got it working with the bare bones of collision and it worked, then I changed bits to this and now it isn’t working. I also tried going back to the original code but still isn’t working
added what the conveyer and item are i did scale the conveyer down so it was easier to work with…