1 of 77

Game Engines Lecture

CMSC498f/838 Presents

Introduction to Unity

2 of 77

Why Use a Game Engine?

Graphics

Physics

Audio

Networking

GUIs

Scripting

Much More!

3 of 77

Why Unity?

4 of 77

"the world’s leading platform for real-time content creation

5 of 77

Beyond Games

6 of 77

Good At Making Games

(Who would have knew)

7 of 77

8 of 77

9 of 77

10 of 77

11 of 77

12 of 77

Unity Platforms

13 of 77

Unity Hub

  • Manage Projects (Templates!) & Unity Versions/Installs
  • Learning Resources
  • Community Resources

14 of 77

Versioning

MAJOR.MINOR.BUGFIX

  • Major (change to API): Not backwards compatible
  • Minor (change to API): Change functionality in a nonbreaking way
  • Bugfix (change in API): fixes bugs

15 of 77

Tech Release vs Long Term Support

Long Term Support (LTS)

  • Stable
  • Supported for two years
  • Released once a year (from latest tech stream)

Tech Release

  • Unstable (but exciting)
  • Supported until the next tech release
  • Released twice a year

16 of 77

Unity Editor Interface

  • A: Toolbar: Administrative logistics
  • B: Hierarchy: Hierarchical representation of everything in the scene
  • C: Game View: What your user will see
  • D: Scene View: What you see (Canvas)
  • E: Overlays: Tools to manipulate scene
  • F: Inspector Window: View properties of anything
  • G: Project Window: all files related to project
  • H: Status Bar: provides notifications about various Unity processes

17 of 77

Toolbar

Controls

  • Unity Account: account settings, developer dashboard, etc
  • Unity Cloud: Create builds on Unity servers
  • Plastic SCM (Version Control System)
  • Play/Pause/Step Game View: Test your game
  • Undo/Redo: Just use CRTL Z & CTRL SHIFT Z
  • Search: Search for anything in project (or outside)
  • Layers: separate and differentiate gameobjects in scene for UI and Scripts
  • Layout: How the interface looks

18 of 77

Status Bar

Controls

  • Most recent message in Console
  • Background Tasks
  • Debugger Mode

19 of 77

Project Window

  • Shows all the files associated with the project
  • Allows you to create, delete, and organize assets
  • Same navigation as OS file explorer
  • Main root folders
    • Assets
    • Packages

20 of 77

Scene View and Overlays

  • Your interactive view into the world you are creatings
  • Easily manipulate gameobjects in your scene visually
    • Manipulation Tools
  • See your scene at different angles
    • Perspective Gizmo
  • Scene Gizmo
  • View Options

“Your canvas”

21 of 77

Navigating Scene View

  • Pan/Moving:
    • Click & Drag
  • Zoom In/Out:
    • Scroll wheel or right-click and drag
  • Orbit: rotate Camera around the current pivot point.
    • Hold Alt (Windows) or Option (macOS), and left-click
  • Fly Through:
    • WASD
  • Focus on Gameobject in Scene
    • Select gameobject and press F

22 of 77

Game View

  • The camera’s perspective
  • Play Pause and Step by One Frame
  • Immediate Feedback in development

“What the user would see”

23 of 77

Hierarchy

  • Shows every GameObjects in scene
  • Create a “hierarchy”, with parent & children GameObjects for organization and grouping
  • Lets you easily create, select, delete, and duplicate GameObjects
  • Can also contain other scenes

24 of 77

Inspector Menu

  • Displays properties and behaviors of currently selected GameObject or Asset
  • Allows you to add, modify, or remove these properties/behaviors (Components!)

25 of 77

Asset Store

Contains library of free and commercial assets that Unity and community members make

  • Assets: Textures, models, animations, entire project examples, tutorials, and Editor extensions.

26 of 77

Package Manager

Package: a container that stores various features and assets

  • Editor Tools and Libraries
  • Assets
  • Runtime tools
  • Templates

Package Manager: view which packages and feature sets are available for installation or already installed in your project

27 of 77

The Three Levels of Unity

Scene

GameObject

Component

Component

Component

GameObject

Component

Component

Component

28 of 77

Game Object

“ Anything which can exist in a Scene”

GameObject

The “building blocks” of your scene that compose things and objects

29 of 77

Components

Components

Scripts that modify the behavior and look of a GameObject

30 of 77

Custom Scripts

31 of 77

Materials

Materials describe the appearance of surface of your mesh

  • Shader Reference
  • Color
  • Textures

32 of 77

Mesh Renderer & Mesh Filter

  • Mesh Filter: Decides the shape of your mesh
  • Mesh Renderer: Renders your mesh based on your material and filter (holds a reference to both)
    • Mesh: Data Type that stores various properties (vertices, tangents, normals, UV Coordinates, color, etc)

33 of 77

Colliders

  • Collision: An event when two colliders intersect with each other with a physics event
    • Trigger: Simply to detect when one collider enters the space of another without the physics event
  • Does not necessarily have the same shape as the mesh

34 of 77

Prefabs

https://docs.unity3d.com/Manual/Prefabs.html

“Blue Print”

Easily modify multiple gameobjects at once

35 of 77

Rigidbody

A Rigidbody provides a physics-based way to control the movement and position of a GameObject

  • Gravity
  • Mass
  • Collision Detection

36 of 77

User Interface

  • Three UI Systems:
    • UI Toolkit: newest based on standard web technologies.
    • Unity UI Package: GameObject-based UI system
    • IMGUI: code-driven UI Toolkit usually used to extend Unity Editor

37 of 77

User Interface Continued

  • UI Components:
    • Canvas: the area that all UI elements should be inside.
    • Text:
    • Scrollbar
    • Image
    • Toggle
    • Etc

38 of 77

Raycast

https://docs.unity3d.com/ScriptReference/Physics.Raycast.html

Invisible line that is sent out at a input position for a inputed distance to trigger a certain behavior

39 of 77

Particle System

https://docs.unity3d.com/Manual/ParticleSystems.html

Component to Render tiny meshes called particles to get a certain visual effect: rain, smoke, fire etc

40 of 77

Supported C# Code Editors

Visual Studio

Visual Studio Code

JetBrains Rider

41 of 77

Script Anatomy

  • Inherits from MonoBehaviour: base class from which every Unity script derives.
    • Allows you use Unity based functions/attributes
    • Start & Update

42 of 77

Script Life Cycle

43 of 77

44 of 77

Important Unity Scripting Concepts

“Custom Components”

  • Unity Event Functions: Called based on events that happen during gameplay
  • Attributes: indicate certain behavior in scene
  • GetComponent: change and manipulate gameobject properties in script
  • UnityEvents: Invoke your own custom events
  • Coroutines: spread tasks across several frames.

45 of 77

Input System

  • Input Action: Asset in your project where you can easily access your different input bindings and actions
    • Action Maps: Define the mappings between a key or a device input slot and an action
      • Binding: the actual hardware change abstracted

46 of 77

Learning Resources

Unity Blog:

Unity Forum:

Unity Answers:

Unity Discord

Unity Scripting API

Unity Manual

47 of 77

Come to the XR Lab (AVW 4176)!

48 of 77

Join XR Club

TerpLink

Discord

Website

49 of 77

VR Development Lecture

CMSC498f/838 Presents

With

50 of 77

What is Virtual Reality?

51 of 77

What is Virtual Reality

Inducing targeted behavior in an organism by using artificial sensory stimulation, while the organism has little or no awareness of the interference.

52 of 77

Virtual World Generator

Receives input from what the user is doing in the real world (ie head movement, controller input etc) and transfer that to the display as an output to maintain the virtual world

53 of 77

ARCore

ARCore

OpenXR

Oculus

WMR

Unity XR SDK

Display

Input

Environment

Faces

Raycast

Camera

Planes

Image Tracking

Object Tracking

Meshing

AR Foundation

XR Interaction Toolkit

Mixed and Augmented Reality Studio

AR

Applications

VR

Applications

54 of 77

Let’s Break it Down!

Provider Implementations

Enable communication between the headset, peripherals, and Unity

XR Plugin Framework

Core features that enable virtual and augmented reality within Unity

Developer Tools

Components and utilities that help you build your application

55 of 77

Creating a VR Project

56 of 77

Display Terminology

Resolution

A measure of the pixel dimensions of the displays

Refresh Rate

The rate at which the headsets show new images

Field of Vision

An angular measure of how much the displays cover your vision

57 of 77

Inside-Out vs Outside-In Tracking

Outside-In Tracking

Use stationary external devices to determine device position/orientation

Inside-Out Tracking

Use cameras and environmental features to determine device position/orientation

58 of 77

Standalone vs Tethered

Tethered

Headset is plugged into a computer which runs the application/games

(less portable, very powerful)

Standalone

Applications and games run directly from the headset with no PC required

(very portable, less powerful)

59 of 77

  • Gamepads
  • Hand Controllers
  • Hand Tracking
  • Additional “Full-Body” Trackers
  • Eye Tracking
  • Face Tracking
  • Haptic Vests/Suits
  • Force-Feedback Gloves
  • Omnidirectional Treadmills

Virtual Reality Peripherals

60 of 77

Disclaimer about macOS Virtual-Reality Development

  • virtual-reality development on a Mac: ✨“bad”
  • You can:
    • Edit a VR Unity project and manipulate it
    • Build and deploy your project for the Meta/Oculus Quest
      • Prototyping slower, debugging painful
      • We can kinda get around this (in a later slide)
  • You cannot:
    • Connect your VR headset to Play Mode (no VR runtime)
    • Run any other VR software or games off of a Mac

61 of 77

Useful Software for Quest Development

Oculus

Connect (tether) a Quest to your PC wired/wirelessly

Oculus Developer Hub

Manages/installs Quest apps and toggle developer features

Virtual Desktop

Alternative wireless VR streaming application, can function over internet

*

62 of 77

Unity Has a Built-In VR Template!

STOP

( DOESN’T WORK OUT OF THE BOX!)

63 of 77

Setting the Right Build Settings (for Standalone)

  • To deploy for the Oculus/Meta Quest 2, you need to change your build settings via:
    • File > Build Settings
  • Select the Android Platform
  • Use the following settings:
    • Texture Compression: ASTC
    • Development Build: ☑️

CTRL

SHIFT

B

64 of 77

Player Settings

  • To ensure that your game doesn’t appear pitch black, we need to edit the Player Settings via:
    • Edit > Project Settings > Player
  • Click the tab:
    • Auto Graphics API: ⬛
    • Minimum API Level: Android 6.0
    • Active Input Handling: Both

65 of 77

Packages

  • Install the following packages:
    • XR Plugin Managment
    • OpenXR Plugin (com.unity.xr.openxr)
    • XR Interaction Toolkit (com.unity.xr.interaction.toolkit)
      • Import Starter Assets Sample

66 of 77

Enable the OpenXR Plugin

  • Open the XR Plugin Management Settings
    • Edit > Project Settings > XR Plug-in Management
  • Go to both the and tabs and ensure that OpenXR is enabled
  • This will tell Unity to use the OpenXR plugin provider to communicate with the VR devices

67 of 77

Add Interaction Profiles

  • We need to add “bindings” for the different controllers that we want to support in the OpenXR settings
    • Edit > Project Settings > XR Plug-in Management > OpenXR
  • In both the and tabs:
    • Add the Oculus Touch Controller Profile
  • In the tab:
    • OpenXR Feature Groups > Oculus Quest Support: ☑️

68 of 77

XR Device Simulator

A component which takes mouse and keyboard input from the user and uses it to drive simulated XR controllers and an XR head mounted display (HMD).

69 of 77

What is the XR Interaction Toolkit?

Enables locomotion systems within your project such as teleportation and “continuous”

Enables interactions between objects within your VR application

70 of 77

What’s this?

  • A “rig” of GameObjects that represents a VR Player
    • XR Origin: A root GameObject that houses and manages the entire rig
    • Camera Offset: Helps adjust the rig according to the player’s height
    • Tracked Devices: Virtual representations of the physical devices
      • The Tracked Pose Driver & XR Controller synchronize the Transform with the device’s location and orientation in the real world.

XR Origin

Camera Offset

VR Headset

Tracked Pose Driver

XR Controller

Left Controller

Right Controller

71 of 77

XR Interaction Toolkit

Oculus Controller

Index Controller

Vive Controller

Abstract Controller

Interactor

Interactable

Interactable

Interactable

XR Interaction Manager

72 of 77

Review

Interaction Manager

Gets new controller input data and updates interactors/interactables

Interactor

Interacts with interactables (selecting and activating)

Interactable

Objects that can be interacted with (e.g. flashlight, ball, gun, etc.)

73 of 77

Interaction States

Hover

The interactable is able to be selected (but isn’t yet)

Select

The interactable has been grabbed/selected by the user

Activate

The user has activated the interactable

(e.g. firing a gun)

74 of 77

Classify these!

Laser Pointer Selector

Hand Grabber

Beach Ball

Flashlight

Laser Gun

75 of 77

Classify these!

Laser Pointer Selector

INTERACTOR

Hand Grabber

INTERACTOR

Beach Ball

INTERACTABLE

Flashlight

INTERACTABLE

Laser Gun

INTERACTABLE

76 of 77

Types of Interactors

Direct

interacting with Interactables that are close

Ray Interactor

interacting with Interactables at a distance

77 of 77

Locomotion

Smooth/Snap

allows the user to smoothly/snap rotate and move their rig continuously

Grab

allows the user to move as if grabbing the whole world around them.

Teleportation

Instantly moving the XR Origin to the desired location on the user's request.