Event Functions

Unity Cheat Sheet: #1

Abhishek Smith

Abhishek Smith

Building Outscal | Land Jobs in the gaming industry | EA, Epic Games, TCS, | CMU, IIT K

Initialization & Lifecycle

  • Awake(): First! Before ANY Start()
  • OnEnable(): Object/Component activation
  • Start(): Before first frame, after ALL Awake()
  • OnDisable(): Component deactivation
  • OnDestroy(): Final cleanup

Update Loops

  • Update(): Every frame
  • FixedUpdate(): Fixed timestep (physics)
  • LateUpdate(): After all Updates

Physics & Collisions

  • OnCollisionEnter(): First contact
  • OnCollisionStay(): During contact
  • OnCollisionExit(): Contact ends
  • OnTriggerEnter(): Enter trigger zone
  • OnTriggerStay(): Inside trigger
  • OnTriggerExit(): Exit trigger

Rendering & Visibility

  • OnBecameVisible(): Enters camera view
  • OnBecameInvisible(): Exits all views
  • OnRenderObject(): After camera render
  • OnWillRenderObject(): Before camera render
  • OnGUI(): UI/Debug rendering

Application Flow

  • OnApplicationFocus(): Window focus
  • OnApplicationPause(): App pause/resume
  • OnApplicationQuit(): Before app closes

Input & Interaction

  • OnMouseEnter(): Mouse enters collider
  • OnMouseOver(): Mouse stays over collider
  • OnMouseExit(): Mouse leaves collider
  • OnMouseDown(): Mouse click on collider
  • OnMouseUp(): Mouse release on collider
  • OnMouseDrag(): Mouse drag on collider

Editor & Development

  • OnDrawGizmos(): Draw debug in Scene view
  • OnDrawGizmosSelected(): Draw when selected
  • OnValidate(): After inspector value change

CRITICAL Pro Tips:

  • Awake() runs before ANY Start() - perfect for manager initialization
  • Never reference other objects in Awake() - they might not be ready
  • Physics ONLY in FixedUpdate()
  • Camera follow in LateUpdate()
  • OnEnable/OnDisable for event subscriptions
  • Input handling belongs in Update()
  • OnValidate() for inspector value validation
  • Use OnDrawGizmos() for debug visualization
  • OnMouseOver() only works with colliders

Common Pitfalls:

  • Running physics in Update()
  • Initializing dependencies in wrong order
  • Missing OnDisable() cleanup
  • Heavy calculations in OnGUI()
  • Forgetting collider requirement for mouse events
  • Not handling OnApplicationPause() on mobile
  • Using OnMouseDrag() for UI elements

Show More