Search code examples
c#unity-game-enginewaitunity-editor

Wait for unityEvent to finish


I am trying to use UnityEvent and wanted to use them for my movement script. Here is a part of what I have:

if(movementEnabled){
   BeforeMovement.Invoke();
   transform.localPosition = upcommingLocalPosition;
   OnMovement.Invoke();
}

My problem here is that I would need the UnityEvent "BeforeMovenent" to end before continuing to the next line, so to make sure all method in it have completed their task before moving.

In short, I am looking for something similar to a Wait() method.

Is there any way I can achieve this using UnityEvent?


Solution

  • UnityEvents are synchronous, so as long as your event listeners aren't doing anything asynchronous you should be fine