Collider casts against runtime generated colliders not working

Hey, I’m generating some mesh colliders for terrain in ECS with MeshCollider.Create(MeshDataArray, CollisionFilter, Material).
I need to perform some collider casts against it, but they refuse to work entirely - which is why my character just falls through it.
On the other hand, “normal” raycasts and rigidbodies work without problems.
The PhysicsDebugDisplay also shows them correctly.
Also, when I switch to Havok, nothing collides with the terrain anymore :face_with_peeking_eye:.

Do I need to perform some special setup for collider casts to work? Or do I need to assign the colliders in a specific group? Currently, I’m just adding a PhysicsCollider, PhysicsWorldIndex and LocalTransform to the terrain entities and set them up in SimulationSystemGroup.

I’ll also attach some screenshots with the component values and scene view.
I’m running out of ideas, so thanks for your help. :slight_smile:

For reference, that’s the system I’m testing the collider casts in the screenshot with:

partial struct RaycastTestSystem : ISystem
{
	void ISystem.OnCreate(ref SystemState state)
	{
		state.RequireForUpdate<PhysicsWorldSingleton>();
	}

	void ISystem.OnUpdate(ref SystemState state)
	{
		new RaycastTestJob()
		{
			physicsWorld = SystemAPI.GetSingleton<PhysicsWorldSingleton>()
		}.ScheduleParallel();
	}

	[WithAll(typeof(RaycastTestTag))]
	partial struct RaycastTestJob : IJobEntity
	{
		[ReadOnly] public PhysicsWorldSingleton physicsWorld;

		public void Execute(in RaycastTestTag position, in LocalTransform transform, in PhysicsCollider collider)
		{
			ColliderCastInput input = new ColliderCastInput(
				collider.Value,
				transform.Position + (math.down() * 4), //Offset so the entity doesn't collide with itself
				transform.Position + (math.down() * 20));

			Debug.Log(physicsWorld.CollisionWorld.CastCollider(input, out ColliderCastHit closestHit));
		}
	}
}



Rotation in the LocalTransform for the runtime-generated collider looks uninitialized (it should be a vector with magnitude 1, not all zero like it is in the screenshot). The default valid rotation you could assign is quaternion.identity

1 Like

Arrrggghh! You’re right, what a stupid mistake.
Thanks a lot!

That fixes the collision cast issue. Now, when I turn on Havok, the rigidbody stops working while the rest works. Huh.

Are you sure your Havok license is working?

Yes, I currently have the student plan and it’s working fine in a subscene that uses authored colliders. Only the runtime-generated colliders are ignored by rigidbodies.

Ok. Since this is essentially a new topic and we will need more information to get to the bottom of this, could you please make a new post about that specific issue and provide a code snippet of the way you create colliders at runtime?

Feel free to ping me in the post so that I can follow-up.

Thanks!

Will do! Might take a while though as I’ll need to simplify the mesh generation part for this.
Thanks for your help. :slight_smile:

1 Like

Yeah no worries :slight_smile:

This is happening to me, I generate my meshcollider inside an OnUpdate now to simplify and remove all the jobs and other variables. It works in editor but does not work in the standalone or console build

Is there a way I can make sure i’m not using havok? It’s not installed as one of my unity packages, I assume it’s not ,I can’t find it anywhere in the settings or preferences