I am trying to make a UI that is keyboard controlled. However, occasionally the focus is lost to a careless mouse movement. So to put the focus back where it was, I’m using:
if (EventSystem.current.currentSelectedGameObject == null)
Apparently, “lastSelectedGameObject” is obsolete. I can find no documentation explaining why, or what I’m supposed to use instead. What should I be using?
I find it ridiculous that this issue hasn’t been addressed in all of this time. There are countless unanswered questions about this on the forums.
After some googling, it seems like the best alternative is to track the currently selected game object and last selected game object.
system = EventSystem.current;
public void Update()
private void GetLastGameObjectSelected()
if (system.currentSelectedGameObject != currentSelectedGameObject_Recent)
lastSelectedGameObject = currentSelectedGameObject_Recent;
currentSelectedGameObject_Recent = system.currentSelectedGameObject;