OPTIMIZE your Unity game using these performance tips | Tutorial

preview_player
Показать описание

--
As my game (Samurado) continues to get bigger and bigger, performance and optimization is something I've been getting more concerned about. So I went on a deep dive to figure out as much as I could about performance, and these are some of the best tips I use/have come across, some are specifically for 2D games, but some are just overall good rules of thumb for any project!

I hope you enjoy!

--
Timestamps:

00:00 - Intro
00:07 - Sprite Atlas and Frame Debugger
01:30 - Tick System
03:57 - Setting up Your Own Benchmark Tests
06:50 - Hashing Strings
08:20 - General Tips

Unity optimization and performance E-Book:

---
---
---

Who We Are-------------------------------------

If you're new to our channel, we're Brandon & Nikki from Sasquatch B Studios. We sold our house to start our game studio, and work full time on building our business and making our game, Veil of Maia.

Don't forget to Subscribe for NEW game dev videos every Monday & Thursday!

Wishlist Samurado!

Follow us on Twitter for regular updates!

#unitytutorial #unity2d #unity3d
Рекомендации по теме
Комментарии
Автор

Hey guys!
Another easy optimization tip that some of you may not know about: Build your game using IL2CPP (instead of Mono, in the Player Settings)
Mono is better for iteration because the build time is faster, but IL2CPP runs faster, so you always want to use that option on any demos/vertical slices/final builds

sasquatchbgames
Автор

Been using Unity for 10yrs, never played with Sprite atlases. I have a survivor style game with 50 to 100 enemies at a time. Each enemy has a canvas and a scroll view with debuffs. I added all of the debuff sprites to an atlas and the performance gain is significant. Thanks!

leonard
Автор

Nice one Brandon!

1) 02:55 There's rarely a need to define custom delegates. System.Action and System.Func are fine.

2) The tick-system is a nice way to reduce overall CPU load, however, it still executes all of them in the same frame, which may lead to microstutters.
If you try this to spread calculations over time, it requires time slicing.

3) Bonus tipp: One common waste of performance and unneccesary memory allocations i see in Unity tutorials are coroutines. Not just because the coroutines themselves add allocations, but so do the closures that happen hidden from the developer. There's a place for coroutines, but coroutines require a reason to be used.

sealsharp
Автор

Never realised you could pack your own sprite atlas in unity!!! Cheers dude 👍

rickiousproductions
Автор

Great stuff Brandon! A couple more tips: You can limit how often something runs inside Update by using a modulus operator on the frameCount: for example: if (Time.frameCount % 2 == 0) will only be true every other frame. You could limit it to every 10th frame by if (Time.frameCount % 10 == 0)...
The other tip, is in addition to using compression, you can reduce the MaxSize of your textures. Like you said, play around with those settings to see if there's any noticeable difference. Also take advantage of the input quality settings for audio clips because you drag that quality slider down before you start to notice any difference, significantly reducing the size of audio files in your game.

gregbradburn
Автор

Great tips, love this type of videos. A lot of youtubers don't explain debugging and optimization, very important concepts. Thank you

Lazzarus
Автор

Tips are good but I would recommend always starting any video on optimisation with the process of setting a frame rate budget on a target system, measure frame rate and fix where there are issues. You can have a thousand draw calls reduced to 2 but the player won't ever see the change from 200FPS to 300FPS.

RobLang
Автор

This is a freaking GOLDEN prize video for every developer in the world! Thanks guys! 😎

beatrageGameSalad
Автор

Great tips! Thank you for making this video!

ragerungames
Автор

Damn this truly hits the nail !

Last week I was trying to optimize some application at work and after a few different ideas, I just thought about a ticker to fix issues related to multithreading and UI, which was effectively a working solution.

As you said, sometimes, bits of code don't have to run as many times as possible in order to keep the application running as fast as possible. Moreover, I find it really convenient to manage the "scope" of a running thread. By handling how many times it can run its code each second, I feel like I have a better grasp on how much performance some logic can take.

This kind of content explained and demonstrated in such ways is so valuable, thanks for these !

LabitokuDev
Автор

love all the different test and results. Great vid man :)

Jacob___THE_Jacob
Автор

The update callback is a neat system. For anyone interested, it's also possible to inject this system into unity's playerloop directly, making it independent of any game manager instances. For Updates that happen irregularly it's better to spread them evenly across frames, so not all update callbacks happen on the same frame.

A small thing on the benchmark, in order to get accurate results you'd want to run the test at least in a single itteration before starting the timer, otherwise you also time the JIT and not the raw execution time of the code you're interested in.
Adding a warmup function to the benchmark base class to run the function under test once would solve this issue completely.

An additional benefit of the SOs for shared data: if all your scripts update in order there is a higher chance it still sits in cache as the CPU has to churn through less memory. It's usually requesting data from main memory that bottlenecks algorithms, not the algorithm itself (unless we start to go into actually large datasets)

nstch-root-a
Автор

I'm already subscribed to the channel. But every video I watch I'm compulsed to subscribe even more...
A- MAZING

mugmugmugtattoo
Автор

I’ve become a fan of you ever since I watched the SO state machine video. That completely changed the way I programmed.

I’ve noticed a great improvement in your content between that video and this one. Great work!

I don’t know if you have heard this but you should have also mentioned that premature optimization is the root of all evil. If the benefits you gain are tiny from making the changes and it makes your code less readable, then don’t make the changes. Only make changes when you have bottle necks or it is easy to write code in the new format you are teaching.

bgoldpanda
Автор

Wow I had no idea about frame debugger, its so useful!! thank you so much

SheCreatesGames
Автор

Great tips! you should make more optimizing videos.

mracipayam
Автор

i used to pack my sprite manually by taking them and importing into photoshop, this gonna save a lot of time, thanks

KIRA-kzpn
Автор

some really nice tips in here. I really appreciate your efforts!

karatepunk
Автор

One note is that the Sprite Atlas will take care of compression when you setup one, so in this case you don't need to do the importer settings setup for each individual sprite.

vazzius
Автор

Thanks for your video <3, it's so helpful! Please make more :3

txown