Coding Conventions in Unity

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

In this video, you'll learn about using coding conventions in Unity to write code that is easier to read and maintain.

#Unity3D #UnityTutorial #GameDevelopment

Coding conventions are an important and often overlooked part of creating games in Unity. Any software project, whether it be a game, website, or business application, should have some sort of conventions defined in order to make it easier to read and maintain. In this video, I share some of my favorite Unity coding conventions in an effort to show how valuable it can be to have a well-defined visual language across an entire project.

My Favorite Unity Assets 💯⤵️

* Disclosure: These are affiliate links, which means I'll receive a commission if you use them to make a purchase.
Рекомендации по теме
Комментарии
Автор

Lol "There's three of us now!?" "You and I work together a lot." 😆👍

beardordie
Автор

Damn, that skype video quality is next level!

josh_swanson
Автор

Can you pitch shift Barles' voice down an octave and give him one of those technicolor hats with the propeller on top please thanks

ewwitsantonio
Автор

Changing to Rider IDE was one of the best choices I made as a programmer, saves time, suggest appropriate changes to my code, and let me set up other conventions that may not be the default ones.

I like these videos, there is always room for improvement when coding in any type of workflow.

Keep up the good work.

IsmaelSerrada
Автор

What I do instead of copy and pasting code, is I retype the code & even modify it as I am going. This way I get a much more intimate experience with each part of the code, and can also understand it better as I'm figuring out how I should break it up, style, & rename all the pieces of it.

subliminalcastillo
Автор

As a C++ dev I feel personally attacked by first brace not being on the same line as a class/function declaration

UsatiyNyan
Автор

As you state in the video having a convention for your code at all is more important than worrying about which convention to use. I wanted to make an argument however for always prepending class member references with "this." (for example a variable declared as private float speed; would be referenced using this.speed. The reason I favor that approach is because "this" is a language feature that can only be interpreted in one way (the way the language interprets it). I've seen many different uses of "_" in unity code and you can find yourself confused when swapping between your own code, unity documentation, and downloaded / copied / tutorial code. Sometimes private members are prepended with "_", sometimes method arguments are prepended with it. I come from Java software development which is where I picked up this standard, however some of the Unity examples also use it (though the unity docs seem to be some of the most inconsistent styled code anywhere). Allowing an IDE such as Rider to provide formatting is also a good argument, however I have not yet switched to Rider myself.


As for public vs private, personally I haven't actually found it to be extremely important to differentiate between them when reading through code, so I don't bother to differentiate their naming. To be clear, I do carefully consider what members should be public or private, but once that contract is established, I don't usually need to consider it any further, so I don't use a naming convention to keep them visually distinct. Knowing which variable is a member and which is a method argument has proven much more valuable to me.


These approaches have done well for me as a hobbyist Unity developer for the past 5-ish years and as a software developer for the past 15. As stated in the video this will always be a divisive topic, and I don't intend to detract from valid arguments for other styles, just offer my own experience.

EricKesterson
Автор

I have to say Infalilible Code I'm glad that I found your channel back in 2016 when I first got interested how GameDev works. I love how you bring sketch comedy format into something well through educational content. I learn a lot through this method please keep it up. :)

CreativeSteve
Автор

In the last couple of days I have been reading about the Microsoft coding conventions, so this video came out at the right time for me!

faythe
Автор

"Wait. There's 3 of us now?"
HAHAHA. That made me laugh so hard that i have a cramp in my chest now.

subliminalcastillo
Автор

Important concept to cover to, and I like the brought up reasons on why to do it:
- Making it easier to read and understand the code (and a well fitting blog post structure analogy)
- thinking about you as a past self/current self and a future self that might come back to the project in the future while perhaps having forgotten a few things about it already.

Thanks for the vid!

fmproductions
Автор

In Visual Studio, use CTRL+K, CTRL+D to autoformat the current file.

shieldgenerator
Автор

I tend to do Public Field > HideInInspector Public Field, Serialized Private Field, Private Field. My logic is the more exposed variables are at the opening of the Script with more secure variables deep within the script. Open > Closed formatting. Think of the script as a box the deeper you dig into the box the harder to get to the items.

DeathxStrike
Автор

I'm working on a conventions video (might be a little more passive aggressive than this video...) and I loved your concept of there always being at least two people working on the project. Do you mind if I quote you with attribution on my video?

Tarodev
Автор

This video formatting is amazing, definitely earned my sub

mrgetrext
Автор

Complaining about m_ while still doing _.

IDEs can colour variables by scope so you don't have to do that.

Otherwise, love the video, great job.

RobLang
Автор

Working with a friend on a project for my thesis, his naming convention SUCKS DICK and I'm sending this to him.
Thanks for the great video Charles (and Barles)

saito
Автор

Personally, I hate Upper case for public members, because Unity`s libraries are written with lower case rule. Why Would you prefer to mess up with both?

neitron
Автор

3:31 I'm going to murder anyone who does this to my code. Nothing triggers me more than braces going below the declaration. It's ugly, inelegant, and almost never makes the code any more readable.

On a brighter note, what's that font you're using? It looks rad!

verified_tinker
Автор

Your videos are great, so much dedication and work on each video you do, amazing please keep it up! :)

JewGames
join shbcf.ru