Skip to content

Understanding ContactListener #1215

Answered by jrouwe
hgfi asked this question in Q&A
Aug 12, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Reading is recommended when OnContactAdded/Persisted is called. At that point you have a reference to the body and you can use Body::GetMotionType.

During OnContactRemoved the bodies may have already been destroyed, so in general it is not safe to access them (this is documented here). As you're apparently tracking how many contacts there are between bodies, you could perhaps use the BodyID's as key and only track pairs you're interested in (ie that have a dynamic body). That way you don't need to read from the bodies when you get a remove callback.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hgfi
Comment options

Answer selected by hgfi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants