lesson 5: GameObject, The Noun
In this lesson we're going to take a look at the all important "GameObject" and the "GameObject" drop-down menu. We'll also discuss "Local/World" coordinates, "Parent/Child" relationships, and learn about "Particle System." At this stage, we're going to progress rapidly, delving into the subjects that will be relevant to our upcoming projects and touch only briefly on the irrelevant.
Fig. 5.1 illustrates the GameObject drop-down menu.
Here we have our GameObject drop-down menu. Many of the most frequently accessed options can be alternately accessed by right clicking within the Hierarchy View or by clicking the View's Create button. The first option, "Create Empty," does exactly that; it creates an empty "GameObject." That should elicit the questions, "what is a GameObject," "why is this one empty," and, "what purpose could an empty GameObject possibly serve?" A GameObject is anything with a "Transform Value." Think of a game object as something in the game that has a physical analogy. Transforming involves being able to move, scale, or rotate an object. So for example; a game character, a game character's gun, the game character's enemy, these are all things that can be moved and rotated and resized. They are GameObjects. The code that allows the player to jump, the gun to shoot, or the enemy to give chase cannot be rotated, it can't be resized, it cannot be moved. Code is not analogous to anything physical. We cannot touch it or otherwise "physically" manipulate code. Game objects, on the other hand, can be "physically" manipulated through modification of their Transform values. GameObjects are nouns. They are the "things" that make up our scene.
An empty GameObject has ONLY transform values, making it very abstract and very empty indeed. It is a single point without dimension!
What purpose can an empty GameObject possibly serve? You can use an empty GameObject to define a point in space for use as a waypoint. You can use it to re-define a mesh's pivot point by specifying the mesh be a child of the empty game object. It can also be used to create an ad hoc folder system in the Hierarchy View. There are a number of very useful dirty hacks that empty GameObjects facilitate either on their own or through the process of parenting. Segue!
This is a good time to speak about parent/child relationships. Throughout the game object drop-down menu, you'll see reference to "Parent", "Child", and siblings. "Create Empty Child," "Center On Children," "Make Parent," "Clear Parent," "Set As First Sibling," and "Set As Last Sibling" can all be safely ignored. There is a far more elegant way to create parent/child relationships which we'll do now.
Having already saved the previous Scene, open Scene sec1Chap5GameObject
There is a red cube named parent and blue cube named child, center them in the Scene View
Fig. 5.2 illustrates the Scene
Select "parent" and add 2 to its Y Transform value (in the Inspector View), note that it moves up slightly
Select "child" and add -1 to its Y value, note that it moves down slightly
In the Hierarchy View, drag text child onto text parent, note that a hierarchical structure results
You've created a Parent/Child relationship!
Fig. 5.3 illustrates the resulting hierarchical relationship
Select child, note that its Transform values are different now because it is in Local Space (ie the world is no longer the center of its coordinate system, the parent is)
Select the parent cube
uncheck/check the Activation Checkbox (the checkbox next to the name parent in the Inspector View), note that both the parent and child cease to exist/exist
Select the parent and add 1 to its Y value, note that both parent and child move together
If you stipulate the parent be an empty game object, it can then serve as a new pivot point (artificial center of mass) or as the top level in an ad hoc folder system that you can collapse and expand. Of course, the child will inherit many of the properties and actions, such as deactivation, that are perpetrated on the parent. Note too that the child is now in local space rather than world space and will go wherever the parent goes.
Local vs. World Space
There are two main coordinate systems in Unity; "World" and "Local" (keep it in the back of your head that in Playmaker, "Self" is used as a synonym for "Local"). The best analogy for World coordinates are the objective directions of North, South, East, and West. For Local the best analogy are the subjective directions of Front, Back, Left, and Right. World coordinates are objective. The center of the world, 0,0,0, its position never changes. Local coordinates are subjective. They assume that a GameObject is the center of its world. Wherever a Local oriented GameObject moves to, it takes its 0,0,0 coordinates with it. For Children, the Parent is the center of its world. Once the Parent/Child relationship is established, the Child is immediately assigned Local coordinates, receiving assignment from the Parent's pivot point.
Fig. 5.4 illustrates the difference between World and Local coordinate systems.
In Fig. 5.4, parent and child cubes both have coordinates 1,1,1. How can this be given that they are in different positions? Despite having the same coordinates, their actual locations are different because the Parent is using World coordinates and the Child's coordinates are Local, centering at its parent. The Parent is offset from its 0,0,0 world coordinates by 1 in every direction, and the Child is offset from its Parent's 0,0,0 coordinates by 1 as well (and consequently by 2 from the center of the World coordinates).
Fig. 5.5 shows the GameObject drop-down menu with the 3D Object sub-menu visible.
The GameObject Menu has stacks of sub-menus. The first such is the 3D Object sub-menu in which we have, unsurprisingly, 3D objects. Cube, Sphere, Capsule, Cylinder, Plane, Quad, can each serve as what is unflattering called "programmer art." These objects can be used as stand-ins until such time as the developer can import the art assets to be used in the final product.
Text Mesh Pro bills itself as "The Ultimate Text Solution for Unity." It is useful for creating the text elements of a User Interface. One of its best features is that the text it creates retains its visual fidelity at any resolution (i.e., it doesn't blur or become blocky when resized or zoomed in-on). Its use is complex enough to warrant its own tutorial section.
The next divisor contains Ragdoll, Cloth has been removed. Ragdoll is a skeletal system for bipedal characters that enables the engine to manipulate the character's limbs as if it were limp, using physics calculations rather than animations.
Terrain is, of course, extremely important as just about every game needs ground. We'll look at a lot of the parameters in terrain creation when we begin to make our FPS Horror Survival Game. Tree(s) are useful Procedurally Generated art assets. Procedural Generation is a process by which the user specifies certain parameters and then the engine creates a randomized art asset or assets within those parameters, all with the click of a button (or two). In the case of Trees, you can paint them onto a terrain en masse, specifying characteristics such as the density of the forest, the color variation between the trees, an average height, and how far trees should be allowed to vary from that norm. Like height, a width average and variance can be specified as well. Wind Zone. Using Wind Zone you can designate an area in which wind will affect certain game objects, such as trees.
3D Text is yet another text creation option. It seems best suited for game world items, for example, text that appears on signs and monitors as opposed to UI elements.
The next sub-menu is 2D Object. The first option is Sprite. A sprite is a planar image with some special properties (such as the ability to be "Sliced"). It is necessary to convert textures to sprites for use with the User Interface. Like a mask, a Sprite Mask is used to conceal parts of a Sprite. Unlike a mask, a Sprite Mask hides the portion of the Sprite it doesn't cover and reveals the parts of the Sprite it does cover! Just as you would tile a floor or wall, so too can you adorn a 2D level with the images included in a Tilemap. In addition to the corresponding image, users can assign physical properties to tiles. There are also ways to automatically orient placement of the tiles according to a set of rules. For example, you can place a ground tile and have any tile placed in the row directly above it become an incline tile. Any tile placed underneath it could automatically be assigned a dirt texture. With this method you can quickly "paint" a level within a grid that is both visually and physically coherent. Tiles are typically square but can be other shapes as well. Hexagonal Point Top Tilemap and Hexagonal Flat Top Tilemap GameObjects correspond to grids comprised of hexagons. In a similar fashion, anything preceded with the descriptor Isometric corresponds to grids comprised of Isometric tiles, which are functionally equivalent to square tiles viewed from an oblique angle. Isometric perspective is used in 2D to represent (typically map-scale) 3D. A good example of this aesthetic can be seen in early Sim City titles.
Effects elicits several special effects choices. At first the vocabulary item Particle System may seem exotic but it quickly reveals itself to be an irreducible term. It's a system of particles. Particles are a series of planes that use partially-transparent materials. They appear, they can move, rotate, tint, scale, and then they disappear. Fire embers, dust motes, bubbles, snow, and smoke can all be made with particle systems. Trail is used to create a trailing effect such as the tail of a shooting star or the exhaust of a rocket. Line creates a line; think laser beam or laser sight.
The next section is labeled Light. Lighting is an incredibly important, often complex and fraught procedure. Lighting is so important that it constitutes an entire profession within the AAA game development community. Lighting cannot be summarized in a single lesson; it will be covered in a non-exhaustive manner in subsequent lessons. The Light types you have to choose from are; Area Light, Directional Light, Point Light, and Spotlight. Area Light is a Pro only feature. Directional Light is a good stand-in for the sun. Point Lights cast light about in all directions for a limited distance as would a candle or unadorned light bulb. Spotlights project light in a single direction in a limited conical area. A Reflection Probe will acquire images of its surroundings for the purpose of texturing reflective surfaces in its proximity. Originally a Component, Light Probe Group now inexplicably spawns its own empty Game Object to which it is attached. Light Probes are used to "bake" lighting information into your scene so that it doesn't have to perform expensive lighting computations at runtime. They are similar to lightmaps, but whereas lightmaps inform textured surfaces, Light Probes store information about the light in empty spaces. This is useful to inform the appearance of dynamic objects passing through those spaces at runtime.
In the Audio sub-menu we have two choices; Audio Source and Audio Reveb Zone. You can use Audio Reverb Zone to designate an area in which you want echos to occur. An Audio Source is simply an empty Game Object with an Audio Source Component. For anything other than ambient sounds, audio files can be attached directly to a GameObject and controlled through Playmaker.
Previously a GameObject Component, Video Player now inexplicably spawns an Empty GameObject with itself attached. It handles typical video file formats such as .mp4 and .mpeg. In the Inspector you can assign those video files as the GameObject's texture. This can be used for cutscenes or in-game video feeds such as might appear on a TV or monitor.
UI is Unity's system for creating graphical User Interfaces. A Graphical User Interface uses visual icons and indicators to facilitate interaction with a software program. Text, Image, Raw Image, Button, Toggle, Slider, Scrollbar, Dropdown, Canvas, Panel, Scrollbar, Scroll Field, Input Field, Text Mesh Pro variants, and Event System comprise Unity's UI system and serve to facilitate player interaction with the developer's completed software. For example, a game's usual HUD (Heads-Up Display) may consist of icons indicating health, a mini-map, and weapon reticle. It may contain clickable buttons that enable weapon selection. These elements would constitute a UI. The User Interface, and in particular its facilitation through Playmaker, will be covered in a subsequent lesson. The Event System is a way to send events to GameObjects according to the input received. It is bundled with UI because it is as a result of interaction with these input elements that events are typically sent. Among its several roles, the Events System manages raycasting and keeps track of which GameObject is selected at any given time. For the most part, we will be using Playmaker to handle these tasks.
If visible, know that the Vuforia Engine dropdown relates solely to Augmented Reality development. I have several videos on the subject of AR on my NickelCityPixels Youtube channel and hope to offer a more comprehensive course offering on the subject soon. AR is however, way outside the scope of this course.
Camera is self-explanatory. When you create a scene, the one GameObject that is included is a Main Camera. Main Camera has special properties that derive from the Tag "Main Camera." A scene can have multiple Cameras (for example, security Cameras) but the Game View will default from the perspective of the Main Camera. Note that the Game View can alternately render a composite of the Main Camera and additional Cameras (typically the UI Camera).
Parent and Prefab topics are addressed comprehensively elsewhere in this course. Parenting is better accomplished by dragging and dropping text in the Hierarchy View than here in the GameObject dropdown menu.
Move To View does just that. If you select a game object and click Move To View, it physically moves the game object to the center of the scene window. It moves it to the focal point of your scene view. This is essentially the reverse of Frame Selected in which your Scene View moves to center the GameObject at its focal point. More often than not, you will want to move the Scene View to the object. It is anticipated then that you will use Frame Selected more often than Move To View. The most efficient way to use Frame Selected is to select the GameObject in the Hierarchy View, hover the mouse cursor over the Scene View, and press “F.”
Align With View will move the game object to the coordinates of the Scene View. This is especially useful for moving a Camera into alignment. If, for instance, you like a particular vista as seen through the Scene View and you want a Camera to see the same, you can select the Camera and click Align With View. Your camera will assume both the location and rotational parameters of your Scene View. If it's not clear yet, Scene View is essentially an invisible camera the developer uses inside the scene. Alternately it may be thought of as the developer's disembodied eyes, eyes with Transform values but without dimension. Align View To Selected is self-explanatory. Toggle Active State essentially turns GameObjects on and off. This is also accomplished with the first checkbox that appears in the Inspector window next to the game object's name, previously mentioned as the Activation Checkbox.
Thus concludes the lesson on the GameObject drop-down menu! We learned the very important concept that GameObjects are "things." They are analogous to real-world matter; think of them as the nouns of our game. We learned several uses for empty GameObjects (waypoints, pivot points, ad hoc folders) and the process by which Parent/Child relationships are established. The difference between World and Local coordinate systems was explained. World coordinates are objective, Local coordinates are subjective and relate to individual GameObjects. We talked about Lights. Terrain and Trees were briefly introduced. Particle Systems and Cameras were discussed. Finally, we learned some important alignment commands. In the next lesson we'll learn how to enable our nouns with verbs!