Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

PhysicsCallbacks.IPreContactCallback.OnPreContact2D

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public void OnPreContact2D(ref PreContactEvent preContactEvent);

Parameters

Parameter Description
preContactEvent The event that occurred, passed by reference so the manifold can be modified.

Description

Called when a contact between a pair of shapes is updated, giving the opportunity to modify the contact manifold before it is solved. Any change written to the manifold is used by the solver this step, and calling Cancel on the event cancels the contact. Modifying the world-space contact points or the point identifiers has no effect, as the solver does not read them.

This is only called for Awake Dynamic bodies and is never called for triggers.

Extreme care must be taken with this callback.

It occurs during the simulation step and can be called from any thread, so it must be thread-safe. During this time the simulation state is undefined for the broadphase, events and so on. Any attempt to perform a write operation on the world results in a deadlock, as the world itself is write locked. Simple read operations on PhysicsBody, PhysicsShape or PhysicsJoint are safe, such as reading velocity or getting the geometry of a shape, however more complex operations involving the world such as performing a query can result in corruption or crashes. Reading PhysicsUserData from any object is a completely safe read operation, so any required information should be encoded there if possible.

If the manifold is left in an invalid state, such as a value that is not a number or an out-of-range point count, the change is discarded and a warning is produced after the step.