title: Switch unity event system target
body: <p>I would like to replace the target of unity's event system with one that i manually designate elsewhere via code.</p>
  
  <p>This is to allow regular unity events to trigger appropriately for a nearby object even though the pointer may not be directly on the target. (Aim assist / pointer snapping/stabilization)</p>
  
  <p>My problem is that even though i update the event system's selected game object with the desired target, the unity event system doesn't trigger as it still believes that the pointer isn't over a target. (Although the in editor event system debug dialog, and Highlight effects (for UI elements) trigger accordingly and shows that the selected target has changed.)</p>
  
  <pre><code>//Raycast to snapped object
  Physics.Raycast(pos, rot, out hitInfo, 20f);
  //Populate pointer event data using current
  PointerEventData ped = new PointerEventData(EventSystem.current);
  
  //Update data using snapped objects data
  ped.pointerCurrentRaycast = new RaycastResult {
     distance = hitInfo.distance,
     gameObject = focusedObject,
     sortingLayer = hitInfo.transform.gameObject.layer,
     worldNormal = hitInfo.normal,
     worldPosition = hitInfo.point
  };
  
  //Update current target - Target changes in unity debug dialog, but has no effect on clickability
  EventSystem.current.SetSelectedGameObject(focusedObject, ped);
  </code></pre>
  
  <p>What am i missing?</p>
  
  <p><strong>-- Edit For Clarification --</strong></p>
  
  <p>I currently use ray-casting and distance based code to snap the pointer to the target on non-GUI components enabling target snapping pointer based selection. Once the non-GUI target is "snapped" i utilize ExecuteEvents.ExecuteHierarchy for IPointerEnter/Exit/Down/Up/Click to manually triggering events as needed.</p>
  
  <p>For GUI component targets though, if i leverage the same custom event code i loose the ability to interact with more complex, dynamic GUI components without multiple workarounds and adding colliders to each GUI element. I'd like to avoid having to re-engineer unity's input module to support pointer snapping as the default input module works quite well out of the box on GUI components once the pointer enters their bounds.</p>
  
  <p><strong>-- Edit 2 --</strong></p>
  
  <p>I should add that i'm using Unity's HoloLensInputModule, and HoloLensInput to handle UI interactions, while using my own raycasts to handle non-ui components.</p>
  
  <p>It appears as though i'll need to extend HoloLensInput.cs's <code>GetGazeScreenPosition()</code> with my snapping code in order to no longer need to be concerned with updating the event system</p>
  
  <p><strong>-- Mostly Resolved --</strong></p>
  
  <p>I've mostly resolved the issue, by extending StandaloneInputModule, and BaseInput and overriding multiple methods throughout their inheritance structure. (It's ugly but works, and is running more efficiently as i'm able to drop unwanted extra RaycastAll calls)</p>
  
  <p>The crux of the matter is to override not only the RaycastAll call buried deep within the inherited classes, but also any time the eventData is requested, or manipulated. The bulk of the changes relate to <code>GetMousePointerEventData()</code>, and <code>ProcessMouseEvent()</code> and almost all method calls chained within including children recursively.</p>
  
  <p>That being said, there is an issue with scrollbars, which jump between min and max scroll. The issue appears to be coming from the pointerEventData.position value that's used internally by the slider after <code>ProcessDrag()'s ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler);</code></p>