10 Things You NEED to Be Doing in Unity

preview_player
Показать описание
A collection of vital tips and techniques I use in Unity every day. Some are Unity specific, while some are just good programming practices. Let me know if I taught you anything!

=========

0:00 Intro
0:08 Serializing components
1:18 Drawing scene gizmos
1:35 Initialization order
2:31 Stop using public fields
4:30 Mod to loop collections
5:04 PlayClipAtPoint
5:55 Limit extern calls with SetPositionAndRotation
6:53 Operator overloading
8:17 Composition
8:56 Don't use lazy naming conventions
Рекомендации по теме
Комментарии
Автор

Every programmer should keep this in mind while coding:
"Code is read much more often than it is written"

finn
Автор

I've also a tip for beginner : don't over focus on optimisations, instead make your game. If your game is not optimised, you can do it later. But if your game is not working because you spent too much time implementing good practices and well designed patterns - over commenting your code, you gonna loose precious time and energy. When you are experienced and you know what are the pros and the cons of using a specific method you will automaticly try to use the best of it. Bu when you're a beginner, just make the game.

bike_n_fish
Автор

Great video! all perfect advice, and reminded me about the serialized properties :)

UnitydCollege
Автор

Your videos have the highest knowledge density. Never fails to amaze me in these short videos.

sewminadilshan
Автор

My man rolled out of bed, threw on a shirt with a hole in it and started spitting C#/Unity knowledge. Love it. Great video!

stephenkirby
Автор

I probably knew the majority of these already, but using the [field:SerializeField] attribute to specify that the backing field should be serialised on a property is actually ingenious shorthand. Thank you so much!

Neonalig
Автор

Thank you, every second from your every video is pure gold diggin... thank you!!! And thank you for the naming convention, I've had my fair share of confusion, bugs, and misreads due to wrong use of naming convention... Thanks for serializing a property, the mod wraparound thing and operator overloading... so useful, and more importantly so nicely explained... thanks.

DePistolero
Автор

OMG! Using the modulus for iteration to avoid overflow is mindblowing. It was so obvious I don't know why I didn't think of it.

funlightfactory
Автор

A quick note with the mod to loop collections section. Using mod like that does have 1 bug with it, and that's the clipIndex could wrap once it hits Int.MaxValue, causing it to not loop correctly, and also since the int is signed, it'll eventually crash once it hits the negative values. Instead I would write it as _clipIndex = (_clipIndex + 1) % _clips.Length, then index directly using _clipIndex.

jamjardavies
Автор

One minor issue with the modulo approach to index cycling is the index variable isn't really an index anymore, more like a counter, and related to that you could potentially run into overflow issues with really big numbers (not that it's really all that likely).

shenlong
Автор

I kept typing out comments to add to what you were saying, only for you to go on and say exactly what I was going to say!

I'm a software developer by trade, and work in C# on a daily basis, building an enterprise product.

Whenever I sit down to learn something about Unity, I end up spending a bunch of time griping about how I don't get the latest c# features, and critiquing (in my head) the actual C# code that's used in many of the tutorials out there (including first party ones!).

It's really refreshing to see someone using C# to its fullest, great video!

buxt-tech
Автор

Naming Conventions have always helped me quickly solve coding issues that crop up during projects, I didn't realize so many people didn't use them until I started entering GameJams.

greyfireocelot
Автор

I've been using unity for quite a long time and did not know most of the tips in this video. Thank you sir🥰

freelancepakistangames
Автор

Along the lines of naming conventions, one thing I think can be really useful is writing out booleans as lines above the check, for example:

var jumpWasPressed = Input.KeyDown("Space")
if(jumpWasPressed) { //do jump stuff}

The code itself is a comment, and it prevents comments/code from getting out of sync.
This is of course a broader topic about variable names in general, but that's one I do that I think would benefit a lot of code since it explains the "why" of the boolean/etc in many cases.

Also, if the variable is within a function scope and you're not returning it or etc, it's not allocating (on heap) or etc, so there is no real performance difference.

BenVanTreese
Автор

Quick note: The "public Type Variable => ReturnValue;" Syntax creates a readonly property, so its not the same as having "public Type Variable {get;private set;}". The difference is, that the readonly property cannot be changed even by the instance itself, it has no setter.

tobihendrix
Автор

Great video! Love love love that you covered the naming conventions again and didn't back down! Soooo important for the exact reasons you mentioned. ❤️

badscotsman
Автор

Great stuff! Thta tip with position and rotation really f'ed me up! Been using unity for years and never knew that function existed!

iwoMalki
Автор

Wow... 3:44 Serialized 'Properties' is huge... I didn't notice that change and I really appreciate you mentioning it. It always bothered me to write a full propery to conform to Unity and C# coding conventions..! Thank You!

Fresch
Автор

Man you are my favorate youtube unity knowledge master! I had no idea they added serialization of get set properties! Keep up the good work!

bluestek
Автор

Another great no nonsense vid :) Took away so many tips from this. Thx

ravd