My question is the following:
- What is the proper way to perform a multithreaded Capsule Collider cast using DOTS?
My objective is the following:
- Perform a series of collision casts before moving the player character to determine valid move locations.
Details:
I am trying to cast a capsule collider within a Entities.ForEach()
loop.
The error I get is usually some variation of the following message:
EntityBodyIndexMap is not declared [ReadOnly] in a IJobParallelFor job. The container does not support parallel writing. Please use a more suitable container type.
The problem is solved if I invoke the method call Schedule()
rather than ScheduleParallel()
at the end of the ForEach loop, while isolating the CollisionWorld
and PhysicsWorld
references outside the ForEach loop.
1 Like
Please try adding .WithReadOnly(world) before .ForEach, that should make the world read-only. Docs are here: Using Entities.ForEach | Entities | 0.17.0-preview.42
1 Like
SOLVED SOLUTION
Thank you! This did the trick!
For future folks interested in the solution, here it is:
World world = World.DefaultGameObjectInjectionWorld;
BuildPhysicsWorld buildPhysicsWorld = world.GetExistingSystem<BuildPhysicsWorld>();
PhysicsWorld physicsWorld = buildPhysicsWorld.PhysicsWorld;
CollisionWorld collisionWorld = physicsWorld.CollisionWorld;
Entities.WithReadOnly(collisionWorld).ForEach((Entity e, ref Translation translation, ref Rotation rotation) =>
{
// Your code here for casting colliders
ColliderCastHit hit = new ColliderCastHit();
bool haveHit = collisionWorld.CastCollider(c, out hit);
});
6 Likes