- Home /
What is the alternative to lastSelectedGameObject?
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)
{
EventSystem.current.SetSelectedGameObject(EventSystem.current.lastSelectedGameObject);
}
Apparently, "lastSelectedGameObject" is obsolete. I can find no documentation explaining why, or what I'm supposed to use instead. What should I be using?
Ever find an answer to this?
@Unity could we get some documentation on what to use in place of lastSelectedGameObject?
Not that I have found at least not a Unity provided equivalent to lastSelectedGameObject. I don't actually recall how I ended up working around the limitation but I think I ended up writing my own solution that is simply tracking the currently selected game object and when it matters testing current verse the previous tests results to deter$$anonymous$$e change.
Its not pretty but as I recall I already had a place do such where I was already tracking the currently selected gameobject so it was just a matter of storing an additional reference for the previously selected and of course not setting that to null when current selected was null or not an object of interest.
Your answer
Follow this Question
Related Questions
UI Element Got & Lost Focus Handling 2 Answers
Force EventSystem to updating when application not in focus 1 Answer
EventSystem OnPointerClick - not working 0 Answers
NullReferenceException after passing InputField gameObject into EventSystem.SetSelectedGameObject() 1 Answer
Which event to use during Drag Threshold fro UI items? 0 Answers