GDnD Wiki

GDnD Wiki

This site is for Ulster University students and staff. Enter the class access password to continue.

Home

❯

wiki

❯

glossary

❯

GetComponent

GetComponent

25 Apr 20261 min read

  • unity
  • csharp
  • scripting

GetComponent<T>() asks Unity for a component of type T on the same GameObject as the script. It is commonly used to cache references such as Rigidbody2D, Animator or AudioSource in Awake or Start. (course lab series, see source-csharp-unity-labs)

If the component is missing, GetComponent returns null. Beginner scripts should check the result and log a clear error before trying to use it.

Related: unity-getcomponent, component, nullreferenceexception, getcomponent-vs-inspector-references


Graph View

Backlinks

  • GDnD Wiki Index
  • Component
  • NullReferenceException

Created with Quartz v4.5.2 © 2026

  • GitHub
  • Discord Community