- Home /
Which monobehaviour functions can be defined as coroutine (except Start)
I know that Start can be coroutine. Can any other monobehaviour function be coroutines?
Answer by Hellium · May 14, 2021 at 01:55 PM
Non exhaustive list
Functions that can be a coroutine
• Start
• OnApplicationFocus (in editor at least, to be confirmed on build)
• OnApplicationPause (to be confirmed)
• OnCollisionEnter(2D)
• OnCollisionExit(2D)
• OnCollisionStay(2D) (Strange, but tested)
• OnTriggerEnter(2D)
• OnTriggerExit(2D)
• OnTriggerStay(2D)
• OnBecameVisible
• OnBecameInvisible
• OnMouseDown
• OnMouseDrag
• OnMouseEnter
• OnMouseExit
• OnMouseOver
• OnMouseUp
• OnTransformChildrenChanged
• OnTransformParentChanged
• OnWillRenderObject
• OnPreCull
• OnPreRender
• OnPostRender
Functions that can NOT be a coroutine
• Awake
• OnEnable
• Update
• FixedUpdate
• LateUpdate
• OnDisable
• OnDestroy
• OnDrawGizmos
• OnDrawGizmosSelected
• OnGUI
• OnMouseUpAsButton
• OnValidate
• Reset
• OnRenderObject
Answer by Llama_w_2Ls · May 14, 2021 at 01:19 PM
If you're using Visual Studio with intellisense, in a new monobehaviour script, type IEnumerator
leave a space and see the auto complete options for the names. Most of them will be On
something methods like OnApplicationEnter
or OnCollisionEnter2D
etc. Generally, it seems to be methods that are attached to an event e.g. OnMouseDown, with the inclusion of the Start method. Hope that clarifies. @pingleconsoledeveloper
Your answer
Follow this Question
Related Questions
Yield return null? 3 Answers
Example of co-routine for documentation 1 Answer
Coroutine? 4 Answers
StopAllCoroutines() stops coroutines in other scripts? -- Other behaviours ?? 1 Answer
Avoid using MonoBehaviour just for StartCoroutine or WWW load 0 Answers