Skip to content

Commit bc02cfa

Browse files
committed
fix(UIPointer): repetitive enter events
When hovering over elements where ExecuteEvents.ExecuteHierarchy does not return a target, the Enter event would fire repetitively. This change ensures the event only fires once for these types of elements. The reason this was happening was because the `pointerEventData` was not being set properly when firing enter for these elements and would trigger again the next time Hover was called. Thanks to @kristianpd for the work on this fix.
1 parent 35b6e7d commit bc02cfa

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Assets/VRTK/Source/Scripts/Internal/VRTK_VRInputModule.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ protected virtual void Hover(VRTK_UIPointer pointer, List<RaycastResult> results
137137
}
138138

139139
GameObject target = ExecuteEvents.ExecuteHierarchy(result.gameObject, pointer.pointerEventData, ExecuteEvents.pointerEnterHandler);
140+
target = (target == null ? result.gameObject : target);
141+
140142
if (target != null)
141143
{
142144
Selectable selectable = target.GetComponent<Selectable>();
@@ -159,14 +161,12 @@ protected virtual void Hover(VRTK_UIPointer pointer, List<RaycastResult> results
159161
pointer.pointerEventData.hovered.Add(pointer.pointerEventData.pointerEnter);
160162
break;
161163
}
162-
else
164+
165+
if (result.gameObject != pointer.hoveringElement)
163166
{
164-
if (result.gameObject != pointer.hoveringElement)
165-
{
166-
pointer.OnUIPointerElementEnter(pointer.SetUIPointerEvent(result, result.gameObject, pointer.hoveringElement));
167-
}
168-
pointer.hoveringElement = result.gameObject;
167+
pointer.OnUIPointerElementEnter(pointer.SetUIPointerEvent(result, result.gameObject, pointer.hoveringElement));
169168
}
169+
pointer.hoveringElement = result.gameObject;
170170
}
171171

172172
if (pointer.hoveringElement && results.Count == 0)

0 commit comments

Comments
 (0)