Hey, I’m having problems with my runtime-generated colliders being ignored by rigidbodies only when Havok is enabled - casts with PhysicsWorldSingleton are working though.
I was able to reproduce the issue with the following system. It only generates a simple plane mesh with MeshDataArray, creates the collider from that and assigns it to the PhysicsCollider.
With Havok and the PhysicsDebugDisplay enabled, add the RuntimeColliderAuthoring to an empty game object in a subscene and place an authored rigidbody above it.
However, if PhysicsCollider and PhysicsWorldIndex are added by a PhysicsShape authoring component and not by myself (via this baker or at runtime), everything works again even though the entity’s values are the same.
Also allowed to ping @daniel-holz here. Writing something simpler that could reproduce the issue was done faster than I anticipated. ![]()
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Physics;
using Unity.Transforms;
using UnityEngine;
using UnityEngine.Rendering;
public class RuntimeColliderAuthoring : MonoBehaviour
{
class Baker : Baker<RuntimeColliderAuthoring>
{
public override void Bake(RuntimeColliderAuthoring authoring)
{
Entity entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent<MeshGenTestTag>(entity);
// I'm adding these components by hand here as in my actual project, I'm creating entities completely at runtime without using Physics authoring.
AddSharedComponent(entity, new PhysicsWorldIndex());
AddComponent(entity, new PhysicsCollider());
}
}
}
public struct MeshGenTestTag : IComponentData { }
partial struct MeshGenTestSystem : ISystem
{
[BurstCompile]
void ISystem.OnCreate(ref SystemState state)
{
state.RequireForUpdate<MeshGenTestTag>();
}
[BurstCompile]
void ISystem.OnUpdate(ref SystemState state)
{
foreach (var (transform, collider) in SystemAPI.Query<RefRO<LocalTransform>, RefRW<PhysicsCollider>>().WithAll<MeshGenTestTag>())
{
Mesh.MeshDataArray meshDataArray = Mesh.AllocateWritableMeshData(1);
Mesh.MeshData meshData = meshDataArray[0];
NativeArray<VertexAttributeDescriptor> vertexAttributes = new NativeArray<VertexAttributeDescriptor>(4, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
// Set vertex attributes
vertexAttributes[0] = new VertexAttributeDescriptor(VertexAttribute.Position, VertexAttributeFormat.Float32, 3, 0);
vertexAttributes[1] = new VertexAttributeDescriptor(VertexAttribute.Normal, VertexAttributeFormat.Float32, 3, 1);
vertexAttributes[2] = new VertexAttributeDescriptor(VertexAttribute.Tangent, VertexAttributeFormat.Float32, 3, 2);
vertexAttributes[3] = new VertexAttributeDescriptor(VertexAttribute.TexCoord0, VertexAttributeFormat.Float32, 2, 3);
meshData.SetVertexBufferParams(4, vertexAttributes);
meshData.SetIndexBufferParams(6, IndexFormat.UInt32);
// Set vertex data
NativeArray<float3> vertices = meshData.GetVertexData<float3>(0);
NativeArray<float3> normals = meshData.GetVertexData<float3>(1);
NativeArray<float3> tangents = meshData.GetVertexData<float3>(2);
NativeArray<float2> uvs = meshData.GetVertexData<float2>(3);
vertices[0] = float3.zero;
vertices[1] = new float3(0, 0, 10);
vertices[2] = new float3(10, 0, 10);
vertices[3] = new float3(10, 0, 0);
normals[0] = math.up();
normals[1] = math.up();
normals[2] = math.up();
normals[3] = math.up();
tangents[0] = math.right();
tangents[1] = math.right();
tangents[2] = math.right();
tangents[3] = math.right();
uvs[0] = float2.zero;
uvs[1] = new float2(0, 1);
uvs[2] = new float2(1, 1);
uvs[3] = new float2(1, 0);
// Set indices
NativeArray<uint> indices = meshData.GetIndexData<uint>();
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
indices[3] = 0;
indices[4] = 2;
indices[5] = 3;
meshData.subMeshCount = 1;
meshData.SetSubMesh(0, new SubMeshDescriptor(0, 6, MeshTopology.Triangles));
// Create and apply collider
BlobAssetReference<Unity.Physics.Collider> colliderBlob = Unity.Physics.MeshCollider.Create(meshData, CollisionFilter.Default, Unity.Physics.Material.Default);
collider.ValueRW.Value = colliderBlob;
meshDataArray.Dispose();
}
state.Enabled = false; // Run this system just once for demonstration
}
}


