Part 02 - Concepts.

By Jamie Chatterton / 2018-06-12

GameObject

These are the basic unit of object. They are almost abstract in definition and are the fundamental thing that hold all other things.

Component

A GameObject is made up of many components

These are the things that define what a GameObject does. Everything that an object does is a Component, in essence. From the way it works, how it looks, how it interacts with other objects, if it makes a noise. Every little details of an object is defined in a Component.

If you need an object to react to a click, you'd define a Script as a Component and attach it to a GameObject.

If an object renders to the screen (i.e. a Camera) you'd create the code required to do the rendering in a script and attach as a Component to a GameObject.

The mechanics of a game are defined as scripts and attached, in the scene, as Components to GameObjects, even if they have no direct impact on the rendering, the audio or any other direct part of the scene, they need to be in the scene to do anything.

GameObjects can be referenced in Components, either as GameObjects, or as references to the types of Components they contain. So, for instance you can refer to a Text component of an Input text area, instead of the whole game object, and refer to it's exposed functionality, instead of the abstract GameObject.

The Serializable fields of a Component are automatically exposed in the editor and can be updated directly in the GUI. They will default to the default value, or the value they are set in the class, but they won't update their default value once it has been created. Something to be aware of when changing code.

Prefab

A Prefab are a kind of GameObject template. They are GameObjects that have had their definition saved out as a file and can be instantiated into the scene as a copy. Instead of being part of the scene, they are part of the project folder structure, in the assets folder. You can attach them as references, in a Component, like any other GameObject, instantiate them, and then they will be fully usable objects in the scene, as they they were there all along. They can also be added to the scene at design time also, and all the references to the Prefab to share common values for attributes, or allow them to be overridden and become slightly detached. So a Prefab may have a different colour for instance.

Scriptable

Another type of special object is called a Scriptable Object.

This is designed to be an object that contains data.

It's made to be saved into the project and can be passed around as data and used to populate other objects as a lightweight GameObject that has none of the overheads of needing processing like they do. They are serialized as GameObjects are and have a few pieces of functionality built in.

3D in Unity

The 3d Axes are X,Y,Z. Positive (+ve) X goes to the right, +ve Y up, +ve Z into the screen

More posts in this series.