Hello everyone,
For the past few weeks after upgrading from XRIT 2 → 3, I started to get a persistent editor-only-bug where when I entered play-mode (only after already having entered & exited play mode 1+ time) my XRIT interactable(s) in my scene would most of time would ‘spawn’ inside of the socket interactors and or hand interactors they had previously been selected by (socketed into)… For my direct hand interactors, this bug would occasionally show itself in selecting objects when I pull the grab button, even when my hands were not overlapping anything.
After a lot of soul searching for the root cause of this— 1) I still have no idea how the trigger colliders are still registering overlaps between entire domain reloads. 2) Let alone why “OnTriggerStay” is still being invoked after the overlaps have ended… Any insights here would be highly appreciated.
Unity Editor 6.0.9f1 w/ XRTK 3.0.4.
Note: This scene only has 2 direct interactors, and 4 interactable with 2-4 colliders each, and 1 trigger collider per direct / socket interactor; as shown in the build photo below there should be 8-16 overlaps per frame — in editor after 5-10 reloads of the level I’m getting 160, I’ve seen this go into the thousands before after extended testing sessions…
Same Code / Unity Version In Windows Build
I’m using a customized direct-interactable I forked off of the ancient preview.4 XRTK; I’ve updated this with every major XRTK release. All of the other XRIT script’s I’m using are vanilla 3.0. Some of these changes include; how parent of the interactable to the controllers in order to make interactable work better with moving platforms. I’ve included it here in case it’s at fault for this at all somehow…
LeetGrabInteractable2.cs (46.3 KB)
I believe this may be due to a bug Inaccurate collision detection in OnTriggerStay when alternating isKinematic and Collision Detection modes in FixedUpdate in Unity that was fixed in 6000.0.10f1. Can you try installing and upgrading to the latest Unity 6 Preview version to see if this problem still happens?
The title of the bug sound like it’s a almost perfect fit as I am setting the collision detection mode of the interactable, and if it’s kinematic immediately after the interactable becomes socketed; and I reverse this as soon as it’s un-socketed…
However after testing in new editor version: after about a dozen entering / exiting cycles, and I’m not seeing any difference in version 6.0.14f1 / XRTK 3.0.5 – (while still changing is Kinematic and the collision detection modes):
Could you go into more detail on what was causing this issue? How can I help here?
Unrelated new bug which was keeping me from upgrading to 6.0.9f1 - 6.0.14f1: I was unable to upgrade to these versions for the past few weeks due to a seperate bug with HDRP’s water decal shader not compiling for builds in VR; however until I temporally disabled all water under all of my quality levels and external builds are working for now…
Ok I’ve further tested this:
- By removing the only code in my entire project which sets if a rigidbody becomes kinematic (I just commented out these two line in my LeetGrabInteractable2 script above):
/// <summary>
/// Setup the <see cref="Rigidbody"/> on this object due to being grabbed.
/// Automatically called when entering the Select state.
/// </summary>
/// <param name="rigidbody">The <see cref="Rigidbody"/> on this object.</param>
/// <seealso cref="SetupRigidbodyDrop"/>
protected virtual void SetupRigidbodyGrab(Rigidbody rigidbody) {
// Remember Rigidbody settings and setup to move
m_WasKinematic = rigidbody.isKinematic;
m_UsedGravity = rigidbody.useGravity;
m_OldDrag = rigidbody.linearDamping;
m_OldAngularDrag = rigidbody.angularDamping;
// I edited this following line so that it never sets the object to kinematic... As I'm just using the velocity tracking movement type.
// This is the only place in the entire solution where isKinematic was being set -- and as I don't need it, I'm trying to remove it as a potential source of bugs
// I got in unity 6.0.9f1 where OnTriggerStay is building and not clearing for sockets and direct interactable in editor; (e.g. not clearing after domain reloads).
// This is the forum post where I was told there was a fix for a similar issue involving isKinematic, CollisionDetectionMode, and OnTriggerStay:
// https://discussions.unity.com/t/xrit-3-xr-direct-socket-interactors-ontriggerstay-calls-still-being-invoked-after-entering-exiting-playmode-multiple-times/1497510/2
//rigidbody.isKinematic = m_CurrentMovementType == MovementType.Kinematic || m_CurrentMovementType == MovementType.Instantaneous;
rigidbody.useGravity = false;
rigidbody.linearDamping = 0f;
rigidbody.angularDamping = 0f;
}
/// <summary>
/// Setup the <see cref="Rigidbody"/> on this object due to being dropped.
/// Automatically called when exiting the Select state.
/// </summary>
/// <param name="rigidbody">The <see cref="Rigidbody"/> on this object.</param>
/// <seealso cref="SetupRigidbodyGrab"/>
protected virtual void SetupRigidbodyDrop(Rigidbody rigidbody) {
// Restore Rigidbody settings
// I edited this following line so that it never sets the object to kinematic... As I'm just using the velocity tracking movement type.
// This is the only place in the entire solution where isKinematic was being set -- and as I don't need it, I'm trying to remove it as a potential source of bugs
// I got in unity 6.0.9f1 where OnTriggerStay is building and not clearing for sockets and direct interactable in editor; (e.g. not clearing after domain reloads).
// This is the forum post where I was told there was a fix for a similar issue involving isKinematic, CollisionDetectionMode, and OnTriggerStay:
// https://discussions.unity.com/t/xrit-3-xr-direct-socket-interactors-ontriggerstay-calls-still-being-invoked-after-entering-exiting-playmode-multiple-times/1497510/2
//rigidbody.isKinematic = m_WasKinematic;
rigidbody.useGravity = m_UsedGravity | m_ForceGravityOnDetach;
rigidbody.linearDamping = m_OldDrag;
rigidbody.angularDamping = m_OldAngularDrag;
}
This had no effect on stopping the OnTriggerStay bug pictured above.
- So I also commented out all of my code which involved in setting the CollisionDetectionMode:
Background on why I was setting this:
As I was previously setting the interactable’ s rigidbody’ to be kinematic when they were socketed (not knowing it wasn’t needed); I was likewise previously getting errors about not being able to update (some property of) kinematic RB’s when they’re socketed and using MovementType.ContiniousDynamic, so added some code to swapped it to use MovementType.Discrete when it was socketed, which for the time being fixed this issue for me.)
– As this previous fix was no longer needed, when I disable it to see if it has any effect on the OnTriggerStay bug pictured above… I found it to have no effect (For both test 1 & 2 I did a full editor reboot to clear all the previous OnTriggerStay calls which won’t clear between multiple playmode enter/exit cycles).
There was a large change to the event pipeline for the PhysX integration in Unity 6 that caused the regression. The fix that went into 6000.0.10f1 resolved the issue of not handling enter and exit events during the same physics step which I was hoping also fixed the bug you are seeing.
You can submit both bugs inside the Unity Editor using Help > Report a Bug for the HDRP Water shader error and the OnTriggerStay firing erroneously.
To get clarity, are you seeing the bugged behavior where the OnTriggerStay is firing when the colliders are no longer overlapping only after entering Play mode the second time, or are you even seeing this the very first time you enter Play mode upon restarting the Unity Editor?
I’m also seeing incorrect OnTriggerStay messages in Unity 6000.0.12f1. I thought it was related to XRIT, but it can be reproduced really easily without XRIT by doing the following steps:
- Create a box collider (trigger) and a non-kinematic rigidbody with a box collider
- Add a script to the trigger that logs to the console from OnTriggerStay if the rigidbody enters the trigger (be sure to check which object is entering the trigger)
- Enter play mode and move the rigidbody inside the trigger
- Exit play mode
- Enter play mode and observe that the message from OnTriggerStay is logged in the console
I have submitted a bug report with a repro project IN-84106
1 Like