You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: provide non Rigidbody contact events and Rigidbody prioritization (#3094)
* fix
Provide an extended IContactEventHandlerWithInfo that allows users to prioritize which object is being collided with as well as being able to determine if the instance should return non-rigidbody contact events.
* update
Adding changelog entry.
* update
Adding associated PR to the entry
* style
Adding XML API documentation.
* fix
Assuring the default non-info contact event handler sets priority to the non-kinematic bodies.
* test
Added validation test for RigidbodyContactEventManager
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/CHANGELOG.md
+4-1
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,10 @@ Additional documentation and release notes are available at [Multiplayer Documen
9
9
[Unreleased]
10
10
11
11
### Added
12
-
12
+
13
+
- Added `IContactEventHandlerWithInfo` that derives from `IContactEventHandler` that can be updated per frame to provide `ContactEventHandlerInfo` information to the `RigidbodyContactEventManager` when processing collisions. (#3094)
14
+
-`ContactEventHandlerInfo.ProvideNonRigidBodyContactEvents`: When set to true, non-`Rigidbody` collisions with the registered `Rigidbody` will generate contact event notifications. (#3094)
15
+
-`ContactEventHandlerInfo.HasContactEventPriority`: When set to true, the `Rigidbody` will be prioritized as the instance that generates the event if the `Rigidbody` colliding does not have priority. (#3094)
13
16
- Added a static `NetworkManager.OnInstantiated` event notification to be able to track when a new `NetworkManager` instance has been instantiated. (#3088)
14
17
- Added a static `NetworkManager.OnDestroying` event notification to be able to track when an existing `NetworkManager` instance is being destroyed. (#3088)
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/Runtime/Components/RigidbodyContactEventManager.cs
+162-6
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,70 @@
6
6
7
7
namespaceUnity.Netcode.Components
8
8
{
9
+
/// <summary>
10
+
/// Information a <see cref="Rigidbody"/> returns to <see cref="RigidbodyContactEventManager"/> via <see cref="IContactEventHandlerWithInfo.GetContactEventHandlerInfo"/> <br />
11
+
/// if the <see cref="Rigidbody"/> registers itself with <see cref="IContactEventHandlerWithInfo"/> as opposed to <see cref="IContactEventHandler"/>.
12
+
/// </summary>
13
+
publicstructContactEventHandlerInfo
14
+
{
15
+
/// <summary>
16
+
/// When set to true, the <see cref="RigidbodyContactEventManager"/> will include non-Rigidbody based contact events.<br />
17
+
/// When the <see cref="RigidbodyContactEventManager"/> invokes the <see cref="IContactEventHandler.ContactEvent"/> it will return null in place <br />
18
+
/// of the collidingBody parameter if the contact event occurred with a collider that is not registered with the <see cref="RigidbodyContactEventManager"/>.
19
+
/// </summary>
20
+
publicboolProvideNonRigidBodyContactEvents;
21
+
/// <summary>
22
+
/// When set to true, the <see cref="RigidbodyContactEventManager"/> will prioritize invoking <see cref="IContactEventHandler.ContactEvent(ulong, Vector3, Rigidbody, Vector3, bool, Vector3)"/> <br /></br>
23
+
/// if it is the 2nd colliding body in the contact pair being processed. With distributed authority, setting this value to true when a <see cref="NetworkObject"/> is owned by the local client <br />
24
+
/// will assure <see cref="IContactEventHandler.ContactEvent(ulong, Vector3, Rigidbody, Vector3, bool, Vector3)"/> is only invoked on the authoritative side.
25
+
/// </summary>
26
+
publicboolHasContactEventPriority;
27
+
}
28
+
29
+
/// <summary>
30
+
/// Default implementation required to register a <see cref="Rigidbody"/> with a <see cref="RigidbodyContactEventManager"/> instance.
31
+
/// </summary>
32
+
/// <remarks>
33
+
/// Recommended to implement this method on a <see cref="NetworkBehaviour"/> component
34
+
/// </remarks>
9
35
publicinterfaceIContactEventHandler
10
36
{
37
+
/// <summary>
38
+
/// Should return a <see cref="Rigidbody"/>.
39
+
/// </summary>
11
40
RigidbodyGetRigidbody();
12
41
42
+
/// <summary>
43
+
/// Invoked by the <see cref="RigidbodyContactEventManager"/> instance.
/// <param name="averagedCollisionNormal">The average normal of the collision between two colliders.</param>
47
+
/// <param name="collidingBody">If not null, this will be a registered <see cref="Rigidbody"/> that was part of the collision contact event.</param>
48
+
/// <param name="contactPoint">The world space location of the contact event.</param>
49
+
/// <param name="hasCollisionStay">Will be set if this is a collision stay contact event (i.e. it is not the first contact event and continually has contact)</param>
50
+
/// <param name="averagedCollisionStayNormal">The average normal of the collision stay contact over time.</param>
/// This is an extended version of <see cref="IContactEventHandler"/> and can be used to register a <see cref="Rigidbody"/> with a <see cref="RigidbodyContactEventManager"/> instance. <br />
56
+
/// This provides additional <see cref="ContactEventHandlerInfo"/> information to the <see cref="RigidbodyContactEventManager"/> for each set of contact events it is processing.
/// Add this component to an in-scene placed GameObject to provide faster collision event processing between <see cref="Rigidbody"/> instances and optionally static colliders.
/// Any <see cref="IContactEventHandler"/> implementation can register a <see cref="Rigidbody"/> to be handled by this <see cref="RigidbodyContactEventManager"/> instance.
112
+
/// </summary>
113
+
/// <remarks>
114
+
/// You should enable <see cref="Collider.providesContacts"/> for each <see cref="Collider"/> associated with the <see cref="Rigidbody"/> being registered.<br/>
115
+
/// You can enable this during run time or within the editor's inspector view.
116
+
/// </remarks>
117
+
/// <param name="contactEventHandler"><see cref="IContactEventHandler"/> or <see cref="IContactEventHandlerWithInfo"/></param>
118
+
/// <param name="register">true to register and false to remove from being registered</param>
0 commit comments