Get event when player navigate in UI Panel

Hi ! I’d like to update some variables when player “select/highlight” a new UI element in Panel.
( I mean if the currently selected object change by pushing an arrow key, currently selected should update ).

How can I do this without checking in Update every frame ?

Thanx !

For future readers, the best solution is not to inherit from Event Trigger, you should implement the event interfaces, since you should only listen to the events you care about. E.g. I want to listen to Select, Deselect, Submit and Navigation events.

public abstract class Slot : MonoBehaviour, ISubmitHandler, ISelectHandler, IDeselectHandler, IMoveHandler
    {
    	public void OnSubmit (BaseEventData eventData)
    	{
    		
    	}
    
    	public void OnSelect (BaseEventData eventData)
    	{
    		
    	}
    
    	public void OnDeselect (BaseEventData eventData)
    	{
    		
    	}
    
    	public void OnMove (AxisEventData eventData)
    	{
    		
    	}
    }

More here:

The EventSystem object in your scene calls OnSelect() and OnDeselect() methods on the UI elements each time you press an arrow key. It seems that you can only use these methods, since the EventSystem does not call a universal event for every change in the currentSelectedGameObject variable.

First, you have to add a new EventTrigger component to the UI element. Then press ‘Add New Event Type’ (you can choose from a lot of events). Then you can add a function to it.

Or you can do this by adding this script to the UI element:

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class uicheck : EventTrigger {

	public override void OnSelect (BaseEventData eventData)
	{
		base.OnSelect (eventData);
		// Call methods when the UI element is selected
	}

	public override void OnDeselect (BaseEventData eventData)
	{
		base.OnDeselect (eventData);
		// Call methods when the UI element is deselected
	}
}

Do not delete base.OnSelect() and base.OnDeselect(), unless you know what you are doing. If you delete those lines, you will lose a lot of important calls which stand for the original functionality.