I have a friend who is a game developer. He said I should write a blog on this topic. That Every Unity developer has stared at a cryptic red Console message at 2 AM. So This guide breaks down the 5 most common Unity errors — what they mean, why they happen, and exactly how to fix them — with annotated console screenshots.
01. Null Reference Exception
Runtime Error · Most Common
Arguably the most famous error in Unity — and all of C# — a NullReferenceException fires when your code tries to access a method or property on an object that is null (doesn’t exist in memory yet, or was never assigned).
NullReferenceException: Object reference not set to an instance of an object
PlayerController.Start () (at Assets/Scripts/PlayerController.cs:14) UnityEngine.Object:Instantiate(Object) ...
Why does it happen? You declared a variable (like a Rigidbody or a script reference) but never assigned it — either in the Inspector or via GetComponent.
❌ Broken Code
public class PlayerController : MonoBehaviour { private Rigidbody rb; void Start() { rb.AddForce(Vector3.up * 10f); // rb is null! Never assigned. } }
✅ Fixed Code
void Start() { rb = GetComponent<Rigidbody>(); // Grab the component first if (rb != null) rb.AddForce(Vector3.up * 10f); }
- Double-click the error in Console to jump to the exact line
- Find every variable used on that line
- Trace back where each one should be assigned
- Use
GetComponent<>()inAwake()or assign via Inspector - Add a null-check guard for safety
💡 Pro Tip
PreferAwake()overStart()for component references — it runs earlier in the lifecycle and reduces dependency order bugs.