Component Communication

Abhishek Smith

Abhishek Smith

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

The Performance Killers:

  • Calling Find() or FindObjectOfType() in Update()
  • GetComponent() every frame
  • Searching entire hierarchies repeatedly
  • Multiple GetComponentInChildren() calls per frame

The Performance Heroes:

  • Cached references in Awake()
  • SerializeField in Inspector
  • GetComponent for local components
  • One-time initialization searches

WHEN TO USE WHAT:

  • 1. GameObject.Find() & FindObjectOfType()
  • One-time setup in Awake()
  • Prototyping & quick tests
  • Not for regular gameplay updates
  • Not for physics or input handling

2. GetComponent<T>()

  • Getting sibling components
  • Initialization in Awake/Start
  • Not for every frame updates
  • Not for repeatedly accessing the same component

3. GetComponentInChildren<T>()

  • One-time setup of hierarchies
  • Prefab initialization
  • Not for continuous parent-child communication
  • Not for frame-by-frame checks

Pro Tips:

  • Cache everything you'll use more than once
  • Use [SerializeField] for direct references
  • Design hierarchies to minimize searches
  • Consider Scriptable Objects for global data

ALL THE COMPONENT COMMUNICATION FUNCTIONS:

Direct References

  • GetComponent<T>()
  • GetComponents<T>()
  • GetComponentInChildren<T>()
  • GetComponentInParent<T>()
  • FindObjectOfType<T>()
  • FindObjectsOfType<T>()

Search Methods

  • Find()
  • FindWithTag()
  • FindGameObjectsWithTag()

Show More