Snap Drop Zone Locked Out State
See original GitHub issueThere’s an odd broken state the snap zones can get into where they can no longer snap new objects into them. The issue happens based on highlighting of the zone itself. Highlighting of a snapzone happens from OnTriggerEnter()
and OnTriggerExit()
calling ToggleHighlight(Collider collider, bool state)
. The problem lies in the fact that the ValidSnapObject()
function checks to see if an object is grabbed. That makes sense for highlighting of an object, but not as much for turning it off. If the holding object is forced out of a grab and moved by an external force before it can be placed (destroyed, shot out of hand, blows up, manually removed, etc.), ToggleHighlight will not pass ValidSnapObject and thus, will not deactivate the highlight and will not allow any other objects to be snapped there because currentValidSnapObject is never cleared out.
I solved it locally like this, but it’s a hack at best:
private void ToggleHighlight(Collider collider, bool state)
{
var ioCheck = ValidSnapObject(collider.gameObject, true);
// E7_MAB we don't care about grabbing state on unhighlight
if (state == false && ioCheck == null) {
ioCheck = ValidSnapObject(collider.gameObject, false);
}
if (highlightObject && ioCheck)
{
GitHub version of VRTK, maybe a month old, not sure Unity 5.4.3
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (9 by maintainers)
Top GitHub Comments
Attached is a script to repro this issue in example 41.
Attach the InvalidSnap.cs component to the red ball.
Place the red ball in the far left snap zone.
Script will force the ball back before a snap can happen.
Observe that no other object can be placed in the spot.
The above code change allows the Unhighlight function in the snap zone to set it back into a usable state since it see the object leave the trigger.
InvalidSnap.zip
PR with resolution: https://github.com/thestonefox/VRTK/pull/1116