Hi,
You use the collider instance IDs to work out which collider is doing what stuff.
E.g., in my code I have various ground colliders, and wheel colliders and body colliders and stuff, so I
//This all lives in a singleton for me, maybe it doesn't need to?
readonly HashSet<int> GroundColliderInstanceIDs = new (); //These are set from various places in my game
readonly HashSet<int> SoftColliderInstanceIDs = new (); //These are set from various places in my game
private void ModificationEvent( PhysicsScene scene, NativeArray<ModifiableContactPair> pairs ) {
foreach ( var pair in pairs ) {
//"One cannot rely on the order of Colliders in a pair." - https://issuetracker.unity3d.com/issues/modifiable-contact-pair-order-is-swapped-when-in-build
var GroundID = GroundColliderInstanceIDs.Contains( pair.colliderInstanceID ) ? pair.colliderInstanceID : GroundColliderInstanceIDs.Contains( pair.otherColliderInstanceID ) ? pair.otherColliderInstanceID : 0; //"is always unique, and never has the value 0" - https://docs.unity3d.com/2023.1/Documentation/ScriptReference/Object.GetInstanceID.html
if ( GroundID != 0 ) {
var nonGroundID = GroundID != pair.colliderInstanceID ? pair.colliderInstanceID : pair.otherColliderInstanceID;
var softID = SoftColliderInstanceIDs.Contains( nonGroundID ) ? nonGroundID : 0;
if ( softID != 0 )
pair.SetSeparation( i, pair.GetSeparation( i ) + maximumGroundSurfacePenetration ); //Or whatever
}
}
I’ve been using stuff like this & looking at normals and face index and stuff for a year+, it seems to work really nicely (I’m on 2021.3.33f1 LTS, 33 fixed some issues; 2022 LTS seems to have some non-contactmod-related phsyics issues I’m keeping an eye on ).