New answer, solved the issue, see comments for clarification:
TextMesh Pro uses Unity's built in EventSystem
. For this reason, de-select and the like are done through the EventSystem
:
EventSystem.current.SetSelectedGameObject(null);
Thus the "OnDeselect" event is called through EventSystem
's selection management, not TextMesh Pro.
When you select something new with the event system, you also need to make sure that something else is not currently selected in a way that locks. There is a protection/lock in EventSystem
, which prevents setting no object selected in this case, but it prints an error:
Attempting to select while already selecting an object.
UnityEngine.EventSystems.EventSystem:SetSelectedGameObject(GameObject)
You should check if it's already selecting another object:
var eventSystem = EventSystem.current;
if (!eventSystem.alreadySelecting) eventSystem.SetSelectedGameObject (null);
Other post where they discuss the 'lock' part of the EventSystem.
Old answer, didn't solve issue but useful for understanding comment trail below:
My understanding
I'm not experienced with TextMesh Pro, so I cannot for sure say how the cycle of events is when you hit the Enter key.
However, you explain that it at the very least calls the "On End Edit" method. I'd look through their documentation and test what other methods it calls, if I was you. Because this should help you get a better overview of what goes on. Which methods are called and so on.
What to do?
The TextMesh Pro documentation shows various methods available, for various parts of its lifecycle/events.
Documentation
One of them is
public void DeactivateInputField()
Another is
protected override void DoStateTransition(SelectionState state, bool instant)
I suspect one of these could be used for deactivating the field as you intend. If you call them manually at the right time.
An example of how to check the locking state of the currently dealt with event, can be seen in this link: https://answers.unity.com/questions/1315276/event-system-setselectedgameobject-error-but-code.html
Screenshot from documentation
