Applying PostTransformMatrix Disable Physics Collider

Applying PostTransformMatrix Disable Physics Collider
What i want to perform is to create non uniform scale colliders for physics.

My Code :

var testBasicBoxPrefab = GetSingleton<TestBasicBoxPrefab>();
                var entity = EntityManager.Instantiate(testBasicBoxPrefab.prefabEntity);
                EntityManager.AddComponentData(entity, new TestBasicBox());
                EntityManager.AddComponentData(entity, new PostTransformMatrix());
              
                var pos = PlayerReference.Player.transform.position +
                          new Vector3(0,1,0) +
                          PlayerReference.Player.transform.forward;
              
                Vector3 randomScale =
                    new Vector3(UnityEngine.Random.Range(0.5f, 2f), UnityEngine.Random.Range(0.5f, 2f), UnityEngine.Random.Range(0.5f, 2f));
              
                PostTransformMatrix ptm = EntityManager.GetComponentData<PostTransformMatrix>(entity);
                ptm.Value = Matrix4x4.TRS(pos, PlayerReference.Player.transform.rotation, randomScale);
                EntityManager.SetComponentData(entity, ptm);

Created Component :

Result : Physics Balls with Rigidbody aren’t blocked by BoxCollider


Expected result : the Ball must be blocked by Physics collider

Tested with Unity Physics 1.0.16, Entities 1.0.16, Unity 2023.2.14f1

Non-uniform scale needs to be included in the actual collider data itself. There isn’t runtime support for dynamic non-uniform scaling of colliders.

How to include non uniform scale in the collider data ? so physics collider pooling won’t be possible :frowning: What i want to achieve is : i have a bunch of building prefabs, containing colliders structures, how to include them at runtime ? i also noticed there is a bug in unity transform conversion in entities 1.0.16, the entity structure is preserved as long as all elements get a scale of 1,1,1 and no rotation. I don’t understand how unity team can pretend unity entities is production ready with this unconvenience. entities seems to works as long as you works with simple unique object, but nested structures are required too for basic purposes, such as integrating collider structures

Not yet. It’s coming very soon in a future release. :slight_smile:

2 Likes

Is the bug you are mentioning in Unity Physics or Entities in general?
Also, do you observe the same bug in the latest 1.2 release? We have made great strides in improving overall stability in the minor released after 1.0 and are continuing to do.
Any additional.information you could provide regarding this issue will be greatly appreciated by the team.

Regarding collider scaling, as mentioned above, we are rolling out a new feature which will allow runtime collider scaling (uniform and non-uniform) very soon.

1 Like

The bug is related to Entities in General (Baking) and Physics related with Colliders Baking. Sorry i did not have time to check with 1.2 release, but the bug is 100% reproductible in this repo ecs-bug-unity-project-example/Assets at main · sachaamm/ecs-bug-unity-project-example · GitHub , open MyTestAlex.unity scene, everything is explained there and the bug is 100% reproductible in this scene. Finally i managed myself to find a solution, i’m baking the collider everything in a single mesh, collecting all colliders from children in a simple script that i’ve made. Currently, DOTS seems to not handle perfectly complex prefab structures with many TRS operations including non uniform scale.

So it definitely sounds like a limitation in the currently available Unity Physics versions for your use case since you can’t easily scale colliders non-uniformly at runtime.
This feature will become available very soon.

Note that as was mentioned above, the PostTransformMatrix is not meant for that purpose.

1 Like