Skip to main content
Two hooks for working with MuJoCo contacts: useContacts for per-frame contact queries, and useContactEvents for enter/exit transitions.

useContacts

Query contacts involving a specific body (or all contacts).

Signature

Usage

With Callback

All Contacts

useContactEvents

Subscribe to contact enter/exit transitions for a body.

Signature

Usage

ContactInfo

Notes

  • Contact data is read from data.contact every physics frame
  • Geom names are cached to avoid repeated WASM string lookups — the cache clears on model change
  • useContactEvents diffs the contact list between frames to detect transitions
  • Contact reads are wrapped in try/catch (can fail with large ncon)
  • For a component-based API, see <ContactListener>