- Home /
Update() executes before OnPointerEnter (IPointerEnterHandler)... Why?
Hi,
I have a logic that requires the IPointerEnterHandler to execute before Update() for a specific thing. According to this execution chart it looks like it should do exactly that. https://docs.unity3d.com/Manual/ExecutionOrder.html
But it doesn't seem to do that when I log it. Strangely enough, if I move the Update() logic to FixedUpdate() it visually seems to work, but the Debug.Log("Update logic did run"); still runs before Debug.Log("IpointerEnter did run"); But with FixedUpdate() this is an expected behavior according to the above chart.
Any ideas to why IPointerEnter seems to run before Update()?
Answer by ben-rasooli · Aug 14, 2020 at 12:03 PM
How did you arrive at this conclusion? Where in that chart says that IPointerEnterHandler should happen before Update? If you're referring to OnMouseXXX, mouse events are not the same as IPointerHandlers
That is exactly how I came to that conclusion.
If IPointerHandlers aren't included in the Input events, where are they situated in the execution order?
Answer by jeppe79 · Aug 14, 2020 at 06:51 PM
Ok, so it seems IPointerEventHandler already has run when Update() is executed and so using logic in Update() that is dependent on IPointerHandler being executed first is only possible if you are starting a fresh life cycle.
So i decided to put the Update() logic into a Coroutine that first waits for the current frame to run to its' end and then restart the logic.
IEnumerator WaitForIPointerEnterHandlerEvent()
{
yield return null; // Wait for one frame
yield return new WaitForEndOfFrame(); // Waits until end of current frame
// Here the IPointerEnterHandler have executed once since the beginning of the Coroutine, if the event hasn't triggered, then we are not hovering over this object and we can execute other code here.
}
Your answer

Follow this Question
Related Questions
How to check which script is executing first 2 Answers
Incorrect Unity Execution Order for OnApplicationQuit? 1 Answer
Problem with TriggerEnter/Exit Execution Order 0 Answers
Execution Order of OnApplicationPause 1 Answer
Issue about transforming animation in animation event and then in update function continuously 0 Answers