Unity Game Engine: How To Guide
Summer 2021
This guide is available digitally: https://go.ncsu.edu/unityguidevr
Table of Contents
What is It? 2
How to Get Unity Started 2
Building a Project 2
Unity’s Interface 4
Creating Gameplay 5
Scenes 5
Game Objects 9
Prefabs 11
Layers 12
Constraints 13
Implications for Animation 17
Lights 17
Rendering Paths 18
Cameras 18
Publishing Builds 19
Other Information? 20
Unity is a 2D/3D modeling software that allows you to code and build these video game/animation elements. Unity utillizes C# for its coding purposes.
To start using Unity, you must download and install Unity Hub, where all of your Unity projects and other assets are stored. Go to the Unity website to download Unity Hub https://unity3d.com/get-unity/download for either a Windows, MacOS, or Linux desktop.
From there, you must install Unity Editor. To do this, go to the Installs tab. For MacOS, it will look like this:
/Applications/Unity/Hub/Editor
For Windows:
C:\Program Files\Unity\Hub\Editor
Once installed, click “Add”, then “Next”, and install the necessary modules for your Unity experience.
For more in-depth installation instructions, go to https://docs.unity3d.com/Manual/GettingStartedInstallingUnity.html
Within Unity Editor, click on “New”, and choose the template with which you want to work with. Name the project, and choose a location to store your project.
Your Projects Tab is stored in the Hub and manages all of your Unity projects. In Unity Editor, to open a project, go to File > Open Project.
Choose a Project Template that fits your project needs. These templates include 2D, 3D, 3D with Extras, High Definition RP, and Universal Render Pipeline. To learn more about these templates, go to https://docs.unity3d.com/Manual/ProjectTemplates.html
If you want to delve deeper into what you can build and code within Unity, click on the Learn tab within Unity Hub. Go to https://docs.unity3d.com/Manual/learn-tab.html to read more about this.
Introducing the Unity Interface
Unity’s interface provides many tools and areas that help regulate and create the gameplay. These include commands and tools such as:
Toolbar: Creates the workspace. The left controls Sceneview and GameObjects. The center allows for pausing, playing, and step controls. The right allows for access to Unity Collaborate, Unity Cloud Services, and your Unity Account.
There is also a layer visibility as well as the Editor layout menu. The Editor layout menu allows you to change the layout for the Editor windows as well as create custom layouts.
Hierarchy window: This is a hierarchical text representation of GameObjects in your Scene. Items within the Scene have an entry in the hierarchy, so the windows are linked. The hierarchy shows how GameObjects attach to each other.
Game view: shows how the final rendered version of the game will look like. You can see for yourself how the scene plays out through the Scene Cameras by clicking the Play button.
Scene view: allows you to visually navigate and manipulate the Scene. This view shows 2D or 3D perspectives, depending on the project being created.
Inspector window: allows you to view and change the properties of the GameObject. The layout and contents of the Inspector window change with every selection of a different GameObject, because each GameObject comes with a different set of properties.
Project window: shows the Assets library that you can use in your project. Imported Assets into the Project will display here.
Status bar: contains notifications for different Unity processes and also provides access to related tools and settings.
Creating GamePlay in Unity can be done by anybody. But, in order to create a seamless GamePlay, there are foundational workflow concepts to understand.
This is where the Unity contents show up when you create your GamePlay. It contains the game assets for a part of a whole game or application.
Every scene opens with a camera and a light source. Scene templates are used to create new scenes, and they are assets that are stored in a project. These are meant to be copied instead of used directly.
To create a new scene from a scene template, go to File > New Scene or hit the Ctrl/Cmd +n shortcut keys.
Components of scenes:
Search field: search by name and find available scene templates
Templates: a list of available templates
Template details: shows information about the template selected
Command bar: has commands and options for creating a new scene from the selected template
To open and edit a template in the Inspector window, click “Edit” link listed under it
Multi-scene editing allows you to have more than one scene open in the editor at once. To open a new scene and add it to the current scene hierarchy, do one of the following:
Click “Open Scene Additive” in the context menu for a scene asset
Drag at least one scene from the Project Window into the Hierarchy Window
Multiple scenes open in the editor window will cause the scenes’ contents to be displayed separately in the hierarchy window. These will appear below a scene divider bar which displays the name of the scene and its save state.
Scenes can be loaded or unloaded to show/hide GameObjects that are contained in the scenes. This is not the same as adding/removing them from the hierarchy window
To save scene, click “File” > “Save Scene” or press the Ctrl/Cmd + S shortcut keys
The context menu in the scene divider bars lets you perform other actions on the selected scene
Scene Templates
Scene templates are just preconfigured scenes implemented at the start of a project.The most basic scene template just contains a camera and a light. You can also create your own scene template for your GamePlay.
Creating new scenes:
To create a new scene from an empty template in the current project folder, go to Asset > Create > New Template
To create a new scene from an empty template in a specific project folder, either:
To create a new scene from an existing scene asset, open the Project window and either:
To create a template from a current scene, go to Menu > File > Save As Scene Template
You can also create scenes from your C# scripts
To learn more about Templates and scene creations, go to https://docs.unity3d.com/Manual/scene-templates-creating.html
Editing Scene Templates
To edit a scene template, select that scene in the Project window and then open it in an Inspector window.
The scene template inspector has different properties:
Customizing new scene creation
You can create a New Scene Template Pipeline script to connect your custom code to the template.
How to connect the script to the template:
You can also use the SceneTemplateAsset.templatePipeline method to connect the script to the template with C# coding.
It must come from the [SceneTemplatePipeline] interface or the [SceneTemplatePipelineAdapter]. The script should implement the events you want to react to, such as BeforeTemplateInstantiation or AfterTemplateInstantiation in your coding script.
Scene Template Settings
To control template Project settings, go to the Project Settings window (Edit > Project Settings) and click Scene Template.
For New Scene settings, go to File > New Scene or use the Ctrl/Cmnd + n shortcut keys.
For Default Types settings, this controls whether Unity duplicates specific types of assets by default when it creates a new scene from a scene template.
To make Unity duplicate a certain type of asset by default, allow the Clone option (2) for that asset type.
To set the default clone/reference behavior for asset types that do not appear in the list of assets, enable/disable the Clone option for All Other Types
To remove an asset type from the list, click Remove.
To add an asset type to the list, either:
In the Add Type field, enter a specific asset type, or Click the Browse button to open a search window where you can find and choose a specific asset tpe.
Click Add to add this asset type to the list.
To go back to Unity’s default type list and settings, click Reset Defaults.
GameObjects are the most important part of the Unity Editor. GameObjects are simply characters and collectible items, even your lightsource, cameras, and special effects that go into your game experience. GameObjects need properties in order to perform tasks or actions or before they can become characters, the environment, or a special effect.
GameObjects are the building blocks in Unity that represent characters, props, and environmental features. They act more as containers for Components than anything else, which implement the functionality.
In order for GameObjects to obtain the properties necessary to become light, props, or a camera, etc., you need to add components to those GameObjects. The kind of object you want to add to your game will depend on the combination of components within that GameObject.
You can use the Unity Scripting API for creating your own components to attach to these GameObjects, such as Box Collider to represent an object’s volume and physicality when colliding with other objects. There are also Mesh Filters and Mesh Renderers for drawing the surface of the cube.
There are pre-constructed objects that you can access by clicking on the GameObject > 3D Object menu (these include primitive shapes, cameras, etc).
There is a Transform component attached to GameObjects that allows you to change the position and orientation of the object, and you cannot remove this.
For more in-depth information about Gameobject use as well as its components, visit https://docs.unity3d.com/Manual/GameObjects.html
Prefabs
Unity’s Prefab system allows for the creation, configuration, and storage of GameObjects with all of their components, property values, and child GameObjects as reusable Assets.
Prefab Assets are templates from which you can create new Prefab instances in the Scene.
Prefabs allow you to automatically keep all the copies in sync should you use a GameObject more than once in a certain way, such as if it’s a prop, part of the scenery, or a non-player character (NPC).
Edits to Prefab Assets are automatically reflected in the instances of the Prefab, which lets you seamlessly make broad changes throughout the whole Project without manually editing every Asset copy.
Nesting Prefabs inside other Prefabs allows for more intricate hierarchies of objects that you can edit at multiple levels.
You can also override settings for individual Prefab instances for creating whatever kind of differentiation for your Prefabs. You can also use variants of Prefabs that allow you to group a set of overrides together into a variation of a Prefab.
Prefabs are great for instantiating GameObjects at runtime that did not exist before in the Scene at the beginning. This can include powerups, special effects, projectiles, or NPCs.
Commonly used Prefabs:
Environmental assets, NPCs, projectiles, and of course the player’s main character.
For more information on Prefabs, go to https://docs.unity3d.com/Manual/Prefabs.html
Layers
Layers in Unity determine which GameObjects can interact with different features as well as with one another. These are mostly used by Cameras to render a part of a scene, and by Lights to illuminate parts of a scene. However, layers can also be used by raycasting to selectively ignore colliders or create collisions.
We can assign new layers to a GameObject. To create a new layer, go to the Tags and Layers window (Edit > Project Settings > Tags and Layers).
After creating a new layer, you can assign that layer to at least one GameObject. GameObjects can only be assigned one layer, but you can apply a layer to several different GameObjects. You can do this in the Tags and Layers window.
To learn more about performances and actions within Layers, go to https://docs.unity3d.com/Manual/Layers.html
Constraint components link position, rotation, or GameObject scale to another GameObject. Constrained GameObjects move, rotate, or scale the GameObject it is linked to.
These are the following types of Constraint components:
Aim: rotate the constrained GameObject to face the linked GameObject
Look At: Rotate the constrained GameObject to the linked GameObject (simplified Aim Constraint)
Parent: Move and rotate the constrained GameObject with the linked GameObject
Position: Move the constrained GameObject like the linked GameObject
Rotation: Rotate the constrained Gameobject like the Linked GameObject
Scale: Scale the constrained GameObject like the linked GameObject
Linking to GameObjects
You can use the Sources list in a Constraint component to specify the GameObjects to link to. This could look like adding a Position Constraint component to the crosshair in order for it to follow your player’s spaceship in a 2D space shooter game. To link this crosshair to the spaceship, go to the Position Constraint component and add the spaceship to the Sources list. As the player moves the spaceship, the crosshair will follow suit.
A Constraint can link to multiple GameObjects.You would then add the GameObjects to illuminate in the Sources list. For example, you can add an Aim Constraint to the Light GameObject. This will shift the light to face the averaged position of its sources.
Unity evaluates source GameObjects in the order that they show up in the Sources list. This order does not affect the Position and Scale Constraints. It will affect, however, the Parent Rotation and Aim Constraints. Reorder the Sources list by dragging and dropping them in the preferred order so that you get your preferred Constraint effects.
You can also constrain a series of GameObjects. For example, if your goal is to get duckling GameObjects to follow a mother duck GameObject, you would:
It is best not to create a cycle of Constraints, however, This will cause unpredictable updates during gameplay.
Setting Constraint Properties
Use the Inspector window to change Constraint properties.
You can use Weight to control the influence of the Constraint. For instance, a weight of 1 will cause the Constraint to update a GameObject at the same rate as its source GameObjects. A weight of 0 removes the effect of the Constraint altogether. Each source GameObject also has an individual weight.
In Constraint Settings, you can use the At Rest properties to specify the X, Y, and Z values to use when Weight is 0 or when the property in Freeze Axes is unchecked.
You can use the Offset properties in Constraint Settings to specify the X, Y, and Z values to use when constraining the GameObject.
You can use the Freeze Axes settings to manipulate which axes the Constraint can actually modify.
Activating and Locking Constraints
Activating a Constraint will allow it to evaluate the position, rotation, or scale of the constrained GameObject.
Locking a Constraint will allow it to move, rotate, or scale the Gameobject. A locked Constraint controls the needed parts of the Transform of the GameObject. You cannot manually move, rotate, or scale a GameObject with a locked Constraint. You cannot edit the Constraint Settings while it's locked.
To manually edit the position, rotation, or scale of a GameObject, unlock the Constraint. If the Constraint is active while unlocked, the Constraint updates Constraint Settings for you as you move, rotate, or scale the constrained GameObject or its source GameObjects.
When adding a Constraint component to a GameObject, the Constraint is inactive and unlocked by default. This lets you tweak the position, rotation, and scale of the constrained and source GameObjects before you activate and lock the Constraint.
The Activate and Zero buttons update Constraint Settings.
Activate saves the current offset from the source GameObjects, then activates and locks the constrained GameObject.
Zero resets the position, rotation, or scale to match the source GameObjects, then activates and locks the constrained GameObject.
Animating and combining Constraints
You can use animation clips to modify the source GameObjects that your constrained GameObject links to. As the animation modifies the source GameObjects, the Constraint modifies your constrained GameObject.
You can also animate properties in a Constraint component. This could look like using a Parent Constraint to move a character’s sword from their hand to their back. Firstly, add a Parent Constraint to the sword GameObject. In the Sources list, link the Constraint to the character’s hand and the character’s spine.
To animate the sword, add keyframes for the weight of each source. To animate the sword moving from back to hand, add keyframes to change the weight of the hand from 0 to 1 with keyframes for the weight of the spine from 1 to 0.
You can add multiple Constraint components to the same GameObject. When updating the GameObject, Unity evaluates Constraint components from first to last as they appear in the Inspector window. A GameObject can only contain one similar Constraint component. For example, you cannot add multiple Position Constraints.
Importing Constraints
Go to the Animation tab of the Import Settings window and check your Import Constraints. When you import FBX files into the Unity Editor from 3D modeling softwares (ex: Autodesk, Maya, MotionBuilder), you can include Constraints.
To accompany each incoming FBX file, Unity attaches a Constraint component and links it to the correct GameObjects.
Adding and Editing Constraints
To add a Constraint component:
To edit a Constraint component:
For more information on Constraints, go to https://docs.unity3d.com/Manual/Constraints.html
You can use Unity’s Animation window and Euler angles to specify rotations during an animation.
Unity’s Animation Window: Unity uses either angles within the Animation window used for different instances.
External Animation Sources: When importing from external sources, these files normally contain rotational keyframe animation in Euler format. Normally Unity resamples these animations and generates a new Quaternion keyframe for every frame in the animation so as to avoid any situations where the rotation between keyframes exceeds a Quaternion’s valid range.
For more information on orientation within Unity, go to https://docs.unity3d.com/Manual/QuaternionAndEulerRotationsInUnity.html
Lights are vital to creating scenes within your GamePlay. Light determines the color and mood of your environment. There might very well be more than one light within a scene you work with.
To add light you can go to GameObject > Light. You then will choose the light format that you wish for your scene from the sub-menu that appears. You can manipulate the light just like a GameObject once it’s part of your scene. You can also add a Light Component to any selected GameObject by clicking Component > Rendering > Light.
There are several options to choose from within the Light Component in the Inspector window.
These paths affect mostly Lights and Shadows, so the rendering path you choose for your specific game requirements can affect the project’s performance.
For more information about Lights and Rendering Paths, go to https://docs.unity3d.com/Manual/Lights.html
There will always be at least one camera per scene within your GamePlay, but you can always add more. These are meant to display the 3D world to the viewer. Numerous cameras can offer you a 2-player splitscreen or create advanced custom effects. You can animate cameras or control their movements with physics.
For more information on cameras, go to https://docs.unity3d.com/Manual/Cameras.html
The Build Settings window has every setting and option needed to publish your build to numerous platforms. From the Build Settings window you can create a Development Build to test your game, as well as publishing a final build.
If you want to adjust the publishing settings for your game’s build, go to File > Build Settings.
You can use the Scenes in the Build panel to control which Scenes Unity includes in the build. Use the Platform section of the window to choose which platform you want to build to, and adjust the settings like the Compression Method. The options offered will depend on the Platform you choose.
Choose the Build and Build And Run button to start building.
You can pick the name and save the location for your game by clicking the Save dialog that appears. Unity might just ask you to choose a folder depending on the platform you build to.
When you Save, Unity will build your game. You can’t save the game into the Assets folder, but you can make a subfolder inside your root folder to contain all of the builds.
To learn more about Builds or GamePlay within Unity, go to https://docs.unity3d.com/Manual/PublishingBuilds.html
The Unity online manual as well as Linkedin learning provides more in-depth information about creating within Unity and learning its interface.
To learn about the Unity Interface, go to https://docs.unity3d.com/Manual/UsingTheEditor.html
To learn about creating gameplay within Unity, go to https://docs.unity3d.com/Manual/CreatingGameplay.html
For step by step instructions on learning Unity, go to https://www.linkedin.com/learning/topics/unity
Or https://learn.unity.com/ and sign in with your Unity login
Looking to get some one-on-one help learning how to develop using Unity and other game engines? Request a technology consultation!
Library staff are available to help: https://www.lib.ncsu.edu/tech-consultation