Inheritance and Update()/Start()/Awake()

This is like complaining that oxygen falls short on its face.

The entire UnityEngine infrastructure builds on GameObjects.

Any subjective observation about them is completely irrelevant. Don’t waste your time.

Every object that Unity returns, GameObject or Component or otherwise, can be used by you to track it.

For instance, if every Enemy GameObject has an EnemyController on it, keep the reference to the EnemyController so you don’t have to go digging for it.

Keep in mind that using GetComponent() and its kin (in Children, in Parent, plural, etc) to try and tease out Components at runtime is definitely deep into super-duper-uber-crazy-Ninja advanced stuff.

This sort of coding is to be avoided at all costs unless you know exactly what you are doing.

If you run into an issue with any of these calls, start with the documentation to understand why.

There is a clear set of extremely-well-defined conditions required for each of these calls to work, as well as definitions of what will and will not be returned.

In the case of collections of Components, the order will NEVER be guaranteed, even if you happen to notice it is always in a particular order on your machine.

It is ALWAYS better to go The Unity Way™ and make dedicated public fields and drag in the references you want.

EDIT: also just noticed this is a necro-post. Don’t do that, it’s against forum rules for a good reason.

If you have an actual problem, make a new post. It’s FREE!

When you make your new post, here is how to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

Do not TALK about code without posting it. Do NOT retype code. Copy/paste and post code properly. ONLY post the relevant code, and then refer to it in your discussion.

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

4 Likes