$ ./guess_the_languageGame Dev
Game Dev · hard · #100

What is the main problem with this loop?

for (int i=0;i<1000;i++) GetComponent<Rigidbody>();
  1. Repeated component lookups are costly
  2. Rigidbody cannot be fetched twice
  3. The loop never actually terminates
  4. GetComponent returns a new object
Cache the reference once instead of calling GetComponent every iteration.
Play Game Dev ▸