- Home /
Change Physics Contact Pair Modes by code?
Is there a way to change Physics>Contact Pair Modes by code. My application needs to use "Default Contact Pairs" and "Enable All Contact Pairs" in differents scenes. I can't figure how to access it.
Thanks
I don't think that's allowed as it's pretty deep in the physics engine, from what I can tell. What kind of situation are you encountering where you need to swap between modes?
Thanks TreyH. I'm using https://assetstore.unity.com/packages/tools/physics/nwh-vehicle-physics-107332, one of the instructions is setting physics: untick "Queries Hit Triggers" and "Enable All Contact Pairs", without this settings the wheel collider don't recognise a trigger as a unsolid object, so the car pass over it as solid object. At sametime, one of my script that uses rayCast "turns crazy" with this configuration. Last night I tested a bit more, so the "main problem" is on "Queries Hit Triggers", and this i can change by code ( Physics.queriesHitTriggers = true ), keeping "Enable All Contact Pairs".
Triggers are not meant to be solid objects, simply zones to activate scripts.
You can change QueryHitTrigger through the physics class though
Answer by lgarczyn · Jan 23, 2020 at 04:16 AM
This doesn't look to be possible currently, not with separate physics scenes nor with Physics settings.
The simplest workaround would be to keep a static variable that states if such collisions are allowed, and for every collisions, check first if collisions are to be ignored, and if so, check that they are both static or kinematic. If they are, ignore the collision.