How to Actually optimize your game in Unity - Complete Game Optimization Guide

The Game Guy
19 Jun 202013:10

Summary

TLDRThis tutorial video guides viewers on optimizing Unity scenes for high performance without sacrificing quality. It starts with basic settings adjustments, such as shadow quality and graphics presets, and progresses to more advanced techniques like static batching, UI element raycast disabling, and shader optimization for mobile devices. The video also covers Unity's lighting settings, demonstrating the use of mixed lighting modes and light baking to achieve significant FPS improvements. Additional tips include physics settings, material adjustments, and the use of subjective lighting mode for dynamic shadow effects.

Takeaways

  • 🎥 The video is a tutorial on optimizing performance in Unity without sacrificing visual quality.
  • 🌟 The tutorial uses a nature scene with trees and stones downloaded from the Unity Asset Store.
  • 🔆 Default settings on the directional light are kept for simplicity, with a minor change to the skybox color.
  • 📊 Initial performance metrics show 30-40 FPS, indicating the need for optimization.
  • 🌑 Shadows are optimized by changing the shadow type to 'Hard Shadows' and reducing shadow strength.
  • 🔧 Graphic settings are adjusted to a medium preset to improve performance without significant visual loss.
  • 🗜️ Texture compression and mip maps are utilized to reduce texture size and improve rendering efficiency.
  • 📏 The far plane of the main camera is adjusted to limit the view distance and reduce the number of objects rendered.
  • 🔨 Static batching is applied to static objects in the scene to reduce draw calls.
  • 🛑 UI elements that are not interactive have raycasting disabled to save on processing time.
  • 💡 For mobile devices, vertex lit shaders are recommended for better performance, with the option to include shadows.
  • 🕹️ Physics settings are optimized by setting collision detection to 'Discrete' and disabling auto-sync transforms.
  • 🌄 Lighting is optimized by using mixed or baked lighting, adjusting light map settings, and using GPU for light baking.
  • ✨ Materials are simplified by disabling smoothness, specular highlights, and reflections to reduce rendering complexity.
  • 🛑 GPU instancing is enabled to improve performance by reducing the computational load on the CPU.
  • 🗑️ Unnecessary light maps are disabled for objects not in 3D space to save memory.
  • 🔍 The subjective mode in Unity is highlighted as useful for dynamic objects that require real-time lighting updates.

Q & A

  • What is the main focus of the video?

    -The video focuses on teaching viewers how to optimize their scenes in Unity to improve performance without losing visual quality.

  • What is the nature of the 'nature take light' mentioned in the video?

    -The 'nature take light' is a lighting asset downloaded from the Unity Asset Store, which the tutorial uses to enhance the scene's environment.

  • What is the initial FPS of the scene before optimization?

    -The initial FPS of the scene is around 30 to 40, which is considered low for the scene.

  • How does the video suggest optimizing shadows in Unity?

    -The video suggests changing the shadow type of the directional light to 'Hard Shadows' and reducing the shadow strength to achieve a softer shadow effect.

  • What graphic settings changes are recommended in the video to improve performance?

    -The video recommends using the 'Medium' preset in the graphic settings, disabling anisotropic textures, setting shadow types to 'Hard Shadows Only', adjusting shadow resolution to 'Medium', and disabling VSync.

  • What is the purpose of adjusting texture maps in Unity as suggested in the video?

    -Adjusting texture maps helps in optimizing the scene by enabling only necessary texture maps, playing with the max size, and using grunge compression to reduce overall size whenever possible.

  • Why is adjusting the far plane distance of the main camera suggested in the video?

    -Adjusting the far plane distance reduces the number of objects that need to be rendered, which can improve performance by not rendering objects that are too far away from the camera.

  • What is the benefit of using static batching in Unity as mentioned in the video?

    -Static batching reduces the number of draw calls by combining multiple static objects into a single draw call, which can significantly improve performance.

  • How does the video suggest optimizing UI elements for performance?

    -The video suggests disabling raycasting on UI elements that are not interactive and setting the Canvas to sleep when not in use to reduce unnecessary checks and calculations.

  • What shader is recommended for mobile devices in Unity according to the video?

    -The video recommends using the 'Vertex Lit' shader with 'Mobile' selected for better performance on mobile devices.

  • What is the final FPS achieved after all the optimization steps in the video?

    -After all the optimization steps, the video achieves more than 500 FPS.

  • What is the purpose of the 'Subjective Mode' in Unity lighting?

    -The 'Subjective Mode' in Unity lighting is useful for cases where static objects do not move, and it allows the shadows to stay in place while dynamic objects like players move around, using different lighting calculations.

Outlines

00:00

📚 Unity Optimization Basics

This paragraph introduces the video's focus on optimizing Unity scenes for performance without sacrificing quality. The creator thanks the audience for reaching 500 subscribers and uses a nature scene from the Unity Asset Store as a practical example. The scene includes trees, stones, and a directional light with default settings, except for a change to the skybox color. The initial FPS is around 30-40, which is considered low, and the tutorial aims to improve this through various optimization techniques.

05:01

🔧 Adjusting Graphics and Shadow Settings

The second paragraph delves into optimizing graphics settings by adjusting shadow types and strengths on the directional light, and selecting medium preset quality settings to improve performance. It also covers disabling vsync, managing texture maps with compression, and adjusting the main camera's far plane distance. The goal is to maintain visual quality while significantly increasing the frame rate, which is achieved by reducing shadow quality, optimizing texture settings, and limiting the camera's view distance.

10:03

🚀 Advanced Performance Enhancements

In this paragraph, the focus shifts to more advanced optimization techniques, such as static batching to reduce draw calls, disabling unnecessary UI element raycast checks, and adjusting physics settings for better performance. The tutorial also touches on shader selection for mobile devices and disabling reflections and specular highlights to save on rendering resources. The use of GPU instancing is introduced to further boost performance. The result is a substantial increase in FPS, demonstrating the effectiveness of the applied optimizations.

💡 Lighting and Final Touches

The final paragraph discusses the lighting settings, explaining the use of mixed lighting for dynamic objects and baked lighting for static elements. It guides through the process of baking lightmaps and adjusting their resolution and size for performance. The tutorial also addresses the subjective lighting mode, which allows for dynamic lighting on static objects, and suggests further optimizations like disabling auto-sync transforms and reducing texture map generation for non-3D objects. The video concludes with a call to action for deeper exploration of lighting settings and support through Patreon.

Mindmap

Keywords

💡Optimizing

Optimizing refers to the process of making something as effective, efficient, or functional as possible. In the context of the video, it relates to improving the performance of a scene within Unity, a game development platform, without sacrificing visual quality. The script mentions various techniques for optimization, such as adjusting shadow quality and using specific graphic settings.

💡Unity

Unity is a cross-platform game engine developed by Unity Technologies, widely used for creating interactive games and experiences. The video's theme revolves around optimizing scenes in Unity to enhance performance. The script provides specific examples of Unity settings and assets, such as the nature take light and directional light, used to achieve optimization.

💡Shadows

In the context of 3D graphics and game development, shadows are the dark areas created when an object blocks light. The script discusses the impact of shadows on performance, suggesting changes to shadow type and strength to achieve a balance between quality and performance in Unity scenes.

💡Quality Settings

Quality settings in Unity allow developers to adjust the visual fidelity and performance of a game. The script mentions changing these settings to medium preset to optimize performance, which includes adjustments to texture resolution, shadow resolution, and shadow cascades.

💡Texture Maps

Texture maps are images applied to 3D models to give the appearance of detail and surface properties. The video script talks about enabling texture maps and adjusting their size and compression to optimize the scene's performance in Unity, without a significant loss in visual quality.

💡Farplane

The farplane, also known as the far clipping plane, is a distance at which objects in a 3D scene are no longer rendered. The script suggests adjusting the farplane distance to reduce the number of objects rendered, which can improve performance by limiting the view distance.

💡Static Batching

Static batching is a technique used in Unity to improve rendering performance by combining multiple static objects into a single draw call. The script describes marking objects as static to take advantage of static batching and reduce the number of draw calls.

💡UI Elements

UI elements refer to the graphical components used to create user interfaces in games, such as buttons, panels, and images. The script advises disabling raycasting and pixel-perfect settings on UI elements that are not interactive to save on performance.

💡Rigidbodies

In Unity, a Rigidbody is a component that allows objects to have mass and be affected by physics forces. The script mentions setting Rigidbody's collision detection mode to 'discrete' for optimization and temporarily making objects kinematic to avoid unnecessary physics calculations during the lighting baking process.

💡Shaders

Shaders are small programs that run on the GPU and determine how the surface of 3D models appear in a scene. The video script discusses using mobile shaders and vertex lit shaders in Unity for optimizing performance on different platforms, with a focus on mobile devices.

💡Lighting Settings

Lighting settings in Unity are used to define how light interacts with objects in a scene. The script covers changing the light mode to 'mixed' for dynamic objects and using 'subtractive' for baked lighting, which is crucial for achieving high performance in Unity scenes with both static and dynamic elements.

💡GPU Instancing

GPU Instancing is a technique that allows the GPU to draw multiple instances of the same object with a single draw call. The script suggests enabling GPU instancing to save CPU power and improve performance in Unity by reducing the number of draw calls.

💡Subjective Lighting Mode

Subjective lighting mode in Unity is a feature that allows for dynamic lighting to follow a specific object, such as a player character, while static objects in the scene use baked lighting. The script explains how this mode can be useful for maintaining performance while providing dynamic lighting effects.

Highlights

Introduction to optimizing performance in Unity without losing quality, celebrating 500 subscribers.

Use of a nature sky light from the Unity Asset Store for realistic environment lighting.

Default settings on the directional light for simplicity and chaining the source from a skybox to color.

Optimizing shadow quality by changing the shadow type to hard shadows and adjusting strength for a soft effect.

Adjusting graphic settings to medium preset for better performance without significant visual compromise.

Disabling vsync to improve performance in Unity projects.

Optimizing texture maps with compression and size adjustments for reduced memory usage.

Setting the far plane distance on the main camera to limit the view distance and reduce rendering load.

Increasing performance through static batching of static scene objects.

Disabling raycast targets and masks on UI elements to prevent unnecessary checks.

Using mobile shaders for Android devices to enhance performance on mobile platforms.

Adjusting light map resolution and size for optimized lighting performance.

Baking lighting with mixed mode for scenes with dynamic objects.

Matching the ambient color for dynamic objects to blend with the baked lighting.

Disabling auto sync transforms in physics settings to save on processing power.

Reducing the use of smoothness, specular highlights, and reflections for performance gains.

Enabling GPU instancing to offload some of the CPU workload.

Disabling light map generation for objects not in 3D space to save resources.

Using crunched textures with reduced size for memory optimization.

Explanation of subjective lighting mode for dynamic and static objects in Unity.

Invitation for further exploration of lighting settings and support through Patreon.

Transcripts

play00:00

in this video I'm going to teach you

play00:01

everything that you need to know about

play00:03

optimizing your again inside of unity

play00:05

to make it super performant without

play00:07

losing inequality and before we get

play00:09

started I just want to thank you all for

play00:11

your love and support as we hit 500

play00:13

subscribers and with that said let's get

play00:19

started

play00:27

so for this tutorial I'm gonna be using

play00:29

this nature take light that I downloaded

play00:32

from the unity asset store and if you

play00:34

guys want to check it out I'll put a

play00:36

link in the description so here's how it

play00:39

looks with a bunch of trees and stones

play00:41

and I've just set them all inside of

play00:43

this environment game object here

play00:45

I've kept default settings on the

play00:48

directional light to make things easier

play00:50

for you and also for the man camera here

play00:53

and also for the Lighting's except for

play00:57

one little change here and I've chained

play00:59

the source from a skybox to color here

play01:04

also if we go to edit project settings

play01:08

quality

play01:09

I've also capitis to its default

play01:11

settings as you can see here alright

play01:17

alright so now if we hit play

play01:20

let's hit play and open up the stats

play01:24

here you can see we get around 30 to 40

play01:28

FPS which is very low considering of our

play01:31

scene also we can reduce these are post

play01:34

calls and matches here so let's just

play01:37

start optimizing the game firstly ever

play01:41

seen has too many shadows as you can see

play01:43

here and they're all at the highest

play01:45

quality level

play01:46

so let's first like the direction light

play01:49

and we can just go ahead and change the

play01:53

shadow type to hard shadows here and we

play01:57

can reduce the strength to like 0.75 to

play02:01

get there soft shadow effect alright so

play02:04

the next thing we can do is go to our

play02:06

graphic settings let's go to edit

play02:10

project settings and here we can see our

play02:13

scene is kind of too perfect so we can

play02:15

reduce the quality a little bit so

play02:18

instead of changing the settings we can

play02:20

choose this medium preset and it will do

play02:23

just fine so let's first get rid of this

play02:26

n isotropic textures and also make sure

play02:29

the and the other thing is said to

play02:31

resemble now let's go down and here make

play02:35

sure the shadows type are set to hard

play02:37

shadows only also you can just bump up

play02:39

the resolution

play02:40

to medium also make sure they're the

play02:44

shadow cascades is said to no cost kids

play02:47

alright and let's also disable this

play02:50

vsync here because we won't be needing

play02:52

it so let's see how it looks and it

play02:58

looks awesome still so we haven't lost

play03:00

any quality yet also to improve the

play03:05

performance make sure your texture maps

play03:07

let's get the texture Maps here instead

play03:10

of textures and I only have one so make

play03:14

sure you enable just 200 MIT Maps on

play03:16

your texture maps come we could also

play03:21

play around with the make size here so

play03:23

let's see let's keep it at 512 for now

play03:29

and also enable this use grunge

play03:32

compression it will help reduce the

play03:34

overall size whenever possible and now

play03:38

let's try this out let's hit apply and I

play03:42

don't think it should change any quality

play03:44

here so we can go maybe a bit too though

play03:47

and it starts to lower the quality so

play03:50

let's just keep it at 512 awesome so now

play03:54

we can select the main camera and here

play03:58

as you can see we don't need to look

play04:00

much far ahead it will just increase the

play04:04

number of objects to welder so let's

play04:06

keep the farplane 8 around 300 let's try

play04:10

300 for now or maybe we could go a

play04:13

little less so 200 yeah I think 200 will

play04:17

do just fine

play04:18

alright so now it's time to test things

play04:21

out so let's see how we're doing and as

play04:26

you can see we are already 50 frames up

play04:28

then 4 but there is still so much we can

play04:32

do to improve the performance like

play04:34

producing the batches here by static

play04:35

batching as most of our scene is pretty

play04:38

much steady so let's like the

play04:42

environment so this is all static so

play04:45

let's like the environment here now

play04:49

either we can select some of them or

play04:51

just mark all of them as a static for

play04:53

everything

play04:54

so hit yes and now there will be marked

play04:56

as a static let's hit play and as you

play05:00

can see there are only 78 witches now

play05:03

and we saved 260 by static bitching cool

play05:06

so if we were to have many static

play05:09

objects in our scene we could do the

play05:11

same for them alright so another cool

play05:14

thing that you could do is let's exit

play05:18

play mode let's lick the canvas here and

play05:22

here select all the UI elements that are

play05:24

not going to be click on so like all the

play05:28

images here and inside the image

play05:31

component does that those degrees rakers

play05:33

targets and masks able to if you want to

play05:35

so the community doesn't keep checking

play05:38

for raycast on these objects every

play05:40

single firm alright and also we could

play05:43

sleep the canvas and disable this pixel

play05:47

perfect here because it doesn't make any

play05:49

difference whatsoever and if we were to

play05:52

have like rigid bodies in our scene so

play05:55

let's add rigid bodies two of our

play05:57

players here so if we had like these

play06:04

rigid bodies up I'm just gonna set them

play06:07

to is kinematic for now what you need to

play06:10

check is you have these collision

play06:13

detection mode set to discreet and not

play06:14

continuous which will save a lot of

play06:18

physics calculation time for unity

play06:20

anyways I don't need them right now so

play06:22

I'm just gonna remove them next thing

play06:26

you could do is if you're building for

play06:27

Android devices go for these shaders and

play06:33

select the mobile shaders and select

play06:36

this vertex lid it is supposed to be one

play06:40

of the most performant shaders in unity

play06:42

for mobile devices and also you could

play06:44

use this for PC if you want to but if

play06:47

you want to keep the shadows you might

play06:49

want to try the vertex lit with

play06:51

directional light which renders the

play06:54

shadows also and if we hit play

play06:59

as you can see it improves the

play07:01

performance a bit more but for this I'm

play07:05

gonna use these standard shaders so

play07:08

let's get rid of this and also you could

play07:10

get rid of the reflections on these

play07:13

materials because we don't want them to

play07:15

be reflective awesome and now for the

play07:18

most important and the frustrating part

play07:20

there's lighting settings

play07:22

so first let's like the directional

play07:25

light here and we will change the mode

play07:28

so if we could either select baked or

play07:30

mixed here so in our case we will select

play07:33

the mix because we have some dynamic

play07:35

objects like these players which will

play07:37

kindly move around in the scene

play07:39

vertically and we only have one light

play07:42

and it weighs less like mixed and leave

play07:45

everything as is go back to the lighting

play07:48

step first let's slide the players here

play07:51

and just disable them for now because we

play07:54

don't need them in the baking process so

play07:57

firstly let's change the lighting mode

play07:59

to subtractive so let's change this from

play08:03

shadow mask to subtractive and I'll just

play08:06

show you what it does in a moment then

play08:09

we have our players in the scene now we

play08:12

can play around with all these settings

play08:14

here I'm gonna keep this light map

play08:16

resolution to as low as 10 or maybe 20

play08:21

will do just fine so you would just play

play08:24

around with all these settings if you

play08:25

want and also I'll set the light map

play08:28

size to 512 pixels for now and make sure

play08:32

the compressed light map is enabled

play08:34

because it will affect the overall size

play08:36

of the light Maps after being pegged and

play08:38

also let's change the light mapper from

play08:41

progressive CPU to GPU here for faster

play08:45

baking time you can play Iran with all

play08:48

these settings if you want I'm gonna

play08:50

leave them as is for now and hit

play08:52

generate it will take a while so don't

play08:55

worry and when it's finished it kind of

play08:59

looks a bit weird it's because they

play09:01

don't have the light my view is but oh

play09:04

we can generate them inside of unity so

play09:06

let's select the models here just right

play09:08

all of them go to inspector panel and

play09:11

inside the models layer

play09:13

scroll down and you will see this

play09:15

generate light my view is enable this

play09:17

and you can see a bunch of settings here

play09:19

so you can play around with them if you

play09:21

wanted they are good as default so their

play09:23

supply and I will just import everything

play09:25

back here and nothing changed so yeah

play09:29

that's because we have to regenerate the

play09:31

lighting so let's just go ahead and

play09:33

leave everything as is and hit generate

play09:37

lighting and it will take a while and

play09:44

voila here goes

play09:47

so it looks awesome but our player

play09:51

character here seem a bit off they are

play09:54

more bright than the rest of the scene

play09:56

and in order to fix that and go to the

play09:59

lighting step find ambient color and it

play10:02

will only affect of our players cut and

play10:04

cuz they are the only dynamic objects

play10:06

here so let's keep this somewhere around

play10:09

here so the player matches the

play10:11

background that's it play now oh that's

play10:16

crazy fast we are now hitting around 500

play10:20

FPS but there's still some changes to be

play10:24

made so let's close this go to physics

play10:28

and make sure the auto sync transforms

play10:31

is disabled because we don't need it all

play10:33

right and also let's light key materials

play10:37

and if possible get rid of the

play10:41

smoothness set to zero and also both

play10:44

these specular highlights and

play10:46

reflections too so let's remove them

play10:49

because we don't need them anyway and

play10:51

also let's enable this GPU instancing to

play10:56

serve some CPU power and I've done the

play10:59

same for this one let's hit play again

play11:01

and here you can see we are getting more

play11:05

than 500 FPS now which is awesome

play11:09

lastly you could select all these parts

play11:12

and make sure you and make sure you

play11:16

disable the generate map map map maps

play11:18

for them because we don't need them

play11:20

because they are not in 3d space and

play11:22

also we could enable this use crunch

play11:26

impressions and play around with just

play11:28

make size let's try to keep this as low

play11:31

as possible so I'm gonna go up to as low

play11:33

as 128 pixels without losing much

play11:36

quality and it would save us a lot of

play11:39

memory and if you want to check this out

play11:44

let's hit play open up the profiler

play11:48

control 7 and here if we click on

play11:52

rendering click on this rendering tab

play11:55

here and you can see all the sides their

play11:58

textures take up so you can see all the

play12:02

stuff here how many batches are there

play12:04

and how many did we save and everything

play12:06

you need to know and here you could see

play12:08

the CPU usage works using more of the

play12:11

CPUs power by using deep their loop top

play12:14

down and not worry about the editor loop

play12:16

because and if you want me to go deeper

play12:18

into this let just let me know in the

play12:20

comment section and finally let's talk

play12:25

about the subjective mode so if I move

play12:31

over play around the scene you can see

play12:33

the shadow move with it but if we I

play12:36

select one of these static objects and

play12:37

try to move it the shadows stay where it

play12:41

is because it's using the backlighting

play12:43

while the player uses the via lighting

play12:45

that's why the subjective lighting mode

play12:48

is useful in cases like these and if you

play12:50

want me to go deeper into lighting

play12:52

settings let me know in the comment

play12:53

section also and also if you want to

play12:56

help me making these videos support me

play12:58

on patreon and until next time see ya

play13:07

you

Rate This

5.0 / 5 (0 votes)

الوسوم ذات الصلة
Unity OptimizationPerformance TipsShadow SettingsGraphics SettingsQuality AdjustmentTexture CompressionCamera SettingsStatic BakingUI OptimizationPhysics SettingsLighting Techniques
هل تحتاج إلى تلخيص باللغة الإنجليزية؟