EventSystem - detect any click NOT on object

I’m using the Unity EventSystem to detect an OnPointerUp event on my object (by implementing the IPointerUpHandler interface) which flags the clicked object as selected - the clicked object adds itself to a static variable that holds the ‘currently selected’ object.

I would like this object to become deselected when the user clicks anywhere other than the currently selected object i.e. the user clicks on the background, the currently selected object is deselected.

Using the Unity EventSystem, how would I achieve this?

I don’t see a way of getting click data from the EventSystem without implementing one of the IPointerHandler interfaces on an actual GameObject. I know I can detect clicks with the ‘standard’ Input.GetMouseButton function, but this does not tell me if the user has clicked on the selected object or not.

As always, I’ve found quite a simple solution within five minutes of submitting the question; hopefully this will be of use to someone.

  1. Implement the IDeselectHandler handler interface.
  2. When selecting an object, call EventSystem.current.SetSelectedGameObject(this.gameObject)
  3. The OnDeselect event handler will be triggered on the previously selected object

Would love to know how to use the old interface to detect that the mouse was clicked at all (not on a specific object)