- Home /
Cancel or Overwrite an EventSystem Selection
I want to "cancel" a Selectable selection.
I have a list of Selectable objects, and in some cases, I need to select one of them when any of them gets selected.
I used ISelectHandler on all, to catch the selection event, and then try to change selection immediately. My problem is that doesn't let me do this while a selection is already happening.
So I figured I'd simply wait for the selection to finish and make the new selection. Like this :
private IEnumerator ReselectObject (GameObject gObject)
{
yield return new WaitUntil (() => EventSystem.current.alreadySelecting == false);
// yield return new WaitForEndOfFrame ();
EventSystem.current.SetSelectedGameObject (gObject);
}
It works, but the selection change is visible. You can see the first object being selected, then selection quickly changing to the next. I could go with changing the navigation of all Selectable objects in the scene, but I don't want that.
Is there any way to "cancel"/"overwrite" a selection ?
It sounds like you might want a custom input handler. https://docs.unity3d.com/ScriptReference/EventSystems.BaseInput$$anonymous$$odule.html
Or that you should change your design since if you click something how should that mean you click something else?
I also don't see the problem with the first object being selected then the selection changing. Since the user did in fact select that object, it should call its code then as a design feature, you want to change the selected object.
I already had changed my design, but was wondering if someone may know a workaround. I'm working on a selection toolset that I'll publish on the Asset Store soon enough. I'll post about it here. Thanks for your feedback.