1 of 64

Intro to Unity Engine�& modern game engine architecture

CPSC 4820/6820 Game Design

Yang Hu

CU GAME Lab

2 of 64

About Me

Game

Designer & Developer

Game Engine & Graphics

Developer

Human-Centered Computing Research

3 of 64

About Me

Game

Designer & Developer

Game Engine & Graphics

Developer

Human-Centered Computing Research

4 of 64

5 of 64

NO!!! Not Yet :P

6 of 64

7 of 64

What is a game engine?

What can game engines do?

A brief Unity walk through

How to code in Unity?

Other game engines (makers)

8 of 64

What is a game engine?

9 of 64

What is a game engine?

Early game engines

reusable code bases

from previous games

Modern commercial

game engines

A tool set

for all game developers

Doom (1993)

Quake(1995)

Unity

Unreal

10 of 64

What can game engines do?

11 of 64

Audio

Models, animations, lights, shadows...

Rendering

Physics

Collisions, movements, gravities...

Input system, animation system, file manager, AI, networking...

What can game engines do?

12 of 64

Audio

Models, animations, lights, shadows...

Rendering

Physics

Collisions, movements, gravities...

What can game engines do?

13 of 64

What can game engines do?

Frame Rate

or

Frame Per Second (FPS)

14 of 64

What can game engines do?

15 of 64

What can game engines do?

60 Images

per second

0.01667 seconds

for 1 image

16 of 64

What can game engines do?

17 of 64

What can game engines do?

18 of 64

What can game engines do?

19 of 64

What can game engines do?

20 of 64

What can game engines do?

21 of 64

What can game engines do?

22 of 64

What can game engines do?

main() {

game_begins();

game_ends();

return 0;

{

23 of 64

What can game engines do?

main() {

game_begins();

while( game_is_running() ) {

begin_frame();

end_frame();

}

game_ends();

return 0;

{

24 of 64

What can game engines do?

main() {

game_begins();

while( game_is_running() ) {

begin_frame();

for( each _object in _scene ) {

_calculate_physics();

_trigger_sound();

_render();

}

end_frame();

}

game_ends();

return 0;

{

25 of 64

What can game engines do?

main() {

game_begins();

while( game_is_running() ) {

begin_frame();

for( each _object in _scene ) {

_calculate_physics();

_trigger_sound();

_render();

}

end_frame();

}

game_ends();

return 0;

{

What if they cannot be done within the frame rate limit?

(in 16.67 milliseconds)

26 of 64

What can game engines do?

while( game_is_running() ) {

begin_frame();

for( each _object in _scene ) {

_calculate_physics();

_trigger_sound();

_render();

}

end_frame();

}

27 of 64

What can game engines do?

28 of 64

What can game engines do?

while( game_is_running() ) {

begin_frame();

for( each _object in _scene ) {

_calculate_physics();

_trigger_sound();

_render();

}

end_frame();

}

29 of 64

What can game engines do?

while( game_is_running() ) {

begin_frame();

for( each _object in _scene ) {

_calculate_physics();

_trigger_sound();

_render();

}

end_frame();

}

30 of 64

What can game engines do?

Object Model

Object Model

Terrain Model

Particle Effect

Object Collider

Object Collider

Terrain Collider

GameObject

Components

Can Move

Can Move

Cannot Move

Empty Object

Object Collider

31 of 64

A brief Unity walk through

32 of 64

A brief Unity walk through

33 of 64

A brief Unity walk through

34 of 64

35 of 64

36 of 64

37 of 64

38 of 64

39 of 64

40 of 64

41 of 64

Create

and

manage

objects

42 of 64

43 of 64

Create

and

manage

objects

44 of 64

45 of 64

3D Model

3D Model

Terrain Model

Particle Effect

Object Collider

Object Collider

Terrain Collider

GameObject

Components

Cannot Move

Move Simulation

Can Move

Cannot Move

46 of 64

47 of 64

3D Model

Object Collider

Can Move

48 of 64

How to code in Unity?

49 of 64

50 of 64

Include namespaces

allow you to use the functions under these namespaces

Class inheritance

Called once when game start

Called for every frame

51 of 64

How to code in Unity

Start()

Start()

Start()

Start()

Update()

Update()

Update()

Update()

Update()

Update()

Update()

Update()

Update()

Update()

Update()

Update()

Render

Render

Render

Render

52 of 64

Let’s make a mini game

53 of 64

A workflow in an Unity Project

54 of 64

A workflow in an Unity Project

1. Play with Unity (right now)

a. Watch tutorials for different game genres

i. 2D platformer, 2D topdown, 3D action, etc

b. Ask yourself: can I do this?

c. Ask your team: can we do this?

i. Find a common ground for your team. Do not try to do everything by yourself.

55 of 64

A workflow in an Unity Project

2. Do mini game jams (preferably offline meeting, do as many times as you can)

THIS IS FUN!!!

a. Find a past game jam theme

i. e.g., GMTK Game Jam on YouTube

b. Do 30 minutes self-brainstorm and 30 minutes discussion to exchange ideas

c. Watch the best games selected

video for that game jam together

d. Ask yourself and your team

i. Can we code

game mechanics like this?

ii. Can we make

art resources like this?

56 of 64

A workflow in an Unity Project

3. Pick your game idea

a. game genre, target experience, art style, narrative, special mechanics, etc.

4. Set up a plan and workflow

a. Number of scenes, levels,

length of the game

b. Amount of codes

c. Number of art resources,

what are they

i.like we need 31 64 x 64

pixel art and 13 UI

elements

57 of 64

A workflow in an Unity Project

5. Regular check-in

a. I recommend everyone to write down what they have done for each week

i. for example, what video tutorial they watched, what Unity experiment they tried, what art resources they have made, etc.

6. Final Note: Make a rough, playable version first, then add details / levels / art resources, etc.

a. This helps you to

more clearly envision

your project and iterate

your ideas

58 of 64

Thanks

59 of 64

1. Play with Unity (right now)

a. Watch tutorials for different game genres

i. 2D platformer, 2D topdown, 3D action, etc

b. Ask yourself: can I do this?

c. Ask your team: can we do this?

i. Find a common ground for your team. Do not try to do everything by yourself.

2. Do mini game jams (preferably offline meeting, do as many times as you can)

THIS IS FUN!!!

a. Find a past game jam theme

i. e.g., GMTK Game Jam on YouTube

b. Do 30 minutes self-brainstorm and 30 minutes discussion to exchange ideas

c. Watch the “best games” video for that game jam with your team

d. Ask yourself and your team

i. Can we code game mechanics like this?

ii. Can we make art resources like this?

3. Pick your game idea

a. game genre, target experience, art style, narrative, special mechanic, etc.

4. Assign roles

5. Set up a plan and workflow

a. Number of scenes, levels, characters, length of the game

b. Number of codes (you should gain a clear idea about this if you have watched some complete Unity tutorials

b. Number of art resources, what are they (like we need 31 64 x 64 pixel art and 13 UI elements)

6. Regular check-in

a. I recommend everyone to write down what they have done for each week

i. for example, what video tutorial they watched, what Unity experiment they tried, what art resources they have made, etc.

7. Final Note: Make a rough, playable version first, then add details / levels / art resources, etc.

a. This helps you to more clearly envision your project and iterate your ideas

60 of 64

using System;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class MoveCube : MonoBehaviour

{

public float speed;

// Start is called before the first frame update

void Start()

{

}

// Update is called once per frame

void Update()

{

float h = Input.GetAxis("Horizontal"); // returns -1 or 1

float v = Input.GetAxis("Vertical"); // returns -1 or 1

Vector3 MovDir = new Vector3(h, 0, v); // something

// like (1,0,0)

MovDir = MovDir * speed * Time.deltaTime; // delta time refers to the time spent during the last frame. This helps you to calibrate strange movements caused by unstable frame rates by binding objects movements to real time.

gameObject.transform.position += MovDir; // update position

}

}

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class LevelClear : MonoBehaviour

{

public int winScale = 10;

void OnCollisionEnter(Collision collision)

{

gameObject.transform.localScale =

new Vector3(winScale, winScale, winScale);

}

}

61 of 64

Note: Some object names here turns into blue. This kind of object is called “prefab”. Whenever you drag an object from hierarchy to the project file window ->, it becomes a prefab, which means a stored blueprint of that object. This is especially useful when you want to respawn an object multiple times or into different variants. You can simply store that blueprint in your spawner object and instantiate it when needed.

62 of 64

Other game engines (makers)

63 of 64

Other game engines (makers)

RPG Maker

(Steam)

64 of 64

Other game engines (makers)