Namespaces in Unity

2020 ж. 18 Сәу.
60 350 Рет қаралды

Sign up for the Level 2 Game Dev Newsletter: eepurl.com/gGb8eP
In this video, you'll learn how to use namespaces in Unity to organize your project.
#Unity3D #UnityTutorial #GameDevelopment
Some developers think you shouldn't use namespaces in Unity, but they can provide a lot of value to medium/large-sized projects. Not only do they help organize your project, but namespaces open the door to Assembly Definitions which can speed up your compilation times dramatically. Additionally, using namespaces in Unity automatically makes any project easier to maintain, scale, and - most importantly - easier to understand.
📦 Download the code at / 36164698
👨💻 Join our community: / discord
❤️ Support the channel: / infalliblecode
My Favorite Unity Assets 💯⤵️
1️⃣ Odin Inspector: assetstore.unity.com/packages...
2️⃣ Shapes: assetstore.unity.com/packages...
3️⃣ Easy Save: assetstore.unity.com/packages...
4️⃣ Dialogue System for Unity: assetstore.unity.com/packages...
5️⃣ Editor Console Pro: assetstore.unity.com/packages...
⚡ Learn more about Unity 3D Plus at prf.hn/click/camref:1100l3e8M/...
👋 Contact me directly at charles@infalliblecode.com
* Disclosure: These are affiliate links, which means I'll receive a commission if you use them to make a purchase.

Пікірлер
  • 14 classes. "That's an awful lot of class files" Me: ...ok

    @Ratstail91@Ratstail914 жыл бұрын
    • Same

      @simonspasskiy@simonspasskiy3 жыл бұрын
    • "When it's this much to work with, it can become a bit overwhelming" Me: ...ok

      @47Mortuus@47Mortuus2 жыл бұрын
  • One of the the most underappreciated Unity channels. Fantastic stuff and great format. Best of luck to you guys, keepe up the great work.

    @adamodimattia@adamodimattia3 жыл бұрын
  • Infallible Code is my new favourite anime :D

    @cok3n@cok3n4 жыл бұрын
  • What an incredible video format. This sort of 1:1 conversation, keeping it upbeat and honest, discussing the pro's and con's of something casually is exactly the sort of experience one gains from a class or mentor. This video format is excellent! Great job guys.

    @alapidis@alapidis2 жыл бұрын
  • Thank god... This time it was not Charles calling Charles 😂🤣😂😂

    @SHOOTINGDNA@SHOOTINGDNA4 жыл бұрын
    • My mental state is starting to stabilize xD

      @InfallibleCode@InfallibleCode4 жыл бұрын
  • Jason is the patron saint of clean code

    @martycarr1477@martycarr14774 жыл бұрын
  • Yet again knocking it out of the park with the examples. It's great to have this as a reference that I can send to new coders having problems, without having to worry about them picking up bad habits from the tutorials.

    @BeeGameDev@BeeGameDev4 жыл бұрын
  • This format reminds me of old school instructional videos but modernized. It's refreshing and easy to stay attentive to. Keep up the great work!

    @yayz_@yayz_2 жыл бұрын
  • I *love* the conversational format of your videos - it is extraordinary for learning such topics. Great work, Charles.

    @EmotionTheory@EmotionTheory2 жыл бұрын
  • I’m loving this format of your videos, terrific job guys! 🙌

    @RomanPapush@RomanPapush4 жыл бұрын
  • Underrated channel, I am learning c# for unity and you content helps me a lot! Keep going :D Hi from France

    @sheppowed4483@sheppowed44833 жыл бұрын
  • When are we getting a full length feature film of this stellar quality?

    @GameDevHQ@GameDevHQ4 жыл бұрын
  • Thanks for these videos. It would really be useful to see a tutorial how to organize code and folders so they can work with assemblies. You touch in this video very briefly on this. Maybe few examples how to split code when there are recursive references in assemblies.

    @lmao01@lmao014 жыл бұрын
  • Thanks so much for showing how to set the namespace both in Unity and Rider. I was ripping my hair out because Rider kept wanting to create new class files with "DefaultNamespace" instead of the namespace I was manually setting for each file.

    @ArgentFox@ArgentFox3 ай бұрын
  • even tough i knew about namespaces; your video is clear and great!

    @silvanpaul2531@silvanpaul25312 жыл бұрын
  • Dude, those game invites in the end of your videos just kill me! Keep up the good work!

    @ufukseyithan@ufukseyithan4 жыл бұрын
  • I like how small and informative it is.

    @alsharefee@alsharefee4 жыл бұрын
  • Oh. wow.. amazing. I was working as a game tester, looking forward to switching to game development, I have little coding experience, your videos are very helpful in learning. Thank you very much, sir.

    @yadav-r@yadav-r2 жыл бұрын
  • Damn. Treasure trove of unity info. Thank you.

    @maple7rees-352@maple7rees-3529 ай бұрын
  • People say Leonardo Dicaprio is going to give up his Oscar after he saw Charles and Jason acting :)

    @eugenemigursky9608@eugenemigursky96084 жыл бұрын
    • They gonna have to eat a raw fish first.

      @DarthStevenus@DarthStevenus3 жыл бұрын
  • You just made Amazing job guys. Keep going on

    @yanndetaf5725@yanndetaf57254 жыл бұрын
  • I really like those videos. I learned a lot from them. Thank you!!

    @MrWursteimer@MrWursteimer4 жыл бұрын
  • Amazing informative and packed Content! Kepp up the amazing work!

    @SqrlyCode@SqrlyCode4 жыл бұрын
  • I wish a tutor conversation would go this well. If I'm being taught then I'll have to ask least 3 question in their first sentence. Worst is in school when the answer is "That's not important right now, let's just focus on this."

    @magnusm4@magnusm44 ай бұрын
  • learned about rider because of this video.

    @daffertube@daffertube Жыл бұрын
  • Quality as top notch as always.

    @moduntilitbreaks@moduntilitbreaks4 жыл бұрын
  • Another great video fellas, keep em coming!

    @erz3030@erz30304 жыл бұрын
  • Amazing video, I have learned so much from it. Very informative and well explained. Immediate like👍

    @sagiziv927@sagiziv9274 жыл бұрын
  • I love these conversation style tutorials! They make the concepts stick in my brain.

    @kirbymia6209@kirbymia62093 жыл бұрын
    • Big agree

      @daffertube@daffertube Жыл бұрын
  • This is fantastic, thank you Jason and Charles (Barles?)!!

    @ClutchGen@ClutchGen3 жыл бұрын
  • your videos is awesome, this is really a skill that is used in the game company

    @noodle-eater@noodle-eater4 жыл бұрын
  • I've never seen a greate format like this and sad for finding 3 years later.

    @mracipayam@mracipayam11 ай бұрын
  • Glad I stumbled across this! Inspired me to set up proper namespaces for my current project. BTW if you are using Visual Studio and don't have Resharper to mass-add namespaces, you can right click (or use your refactor hotkey) above a class name to add an individual script to a namespace as a refactoring action. At least for me the property window didn't work, apparently Unity likes to take control of it. If you have a ton of scripts, maybe you could open the properties by closing Unity first; I didn't try it.

    @BenightedAlizar@BenightedAlizar9 ай бұрын
  • I recently made a Python script to remove all the namespaces from my files after doing research that using namespaces weren't really needed. Note that this wasn't any layered namespaces, just a single root namespace for everything. And yes, it definitely made me feel more legit to use a namespace lol. It feels like something that should be done at the end of a project's life, during the optimisation phase. I didn't know it could speed up compile times. That *might* be useful if I'm building a lot, though I can imagine it would be a pain to manage.

    @Kramlets@Kramlets4 жыл бұрын
  • I dont know why, but me being the third person listening to your conversation just feels more natural than standart tutorial.

    @logiis2377@logiis2377 Жыл бұрын
  • Okay, I'm in the middle of a project that didn't start with a root namespace and I'm using Visual Studio for my editor. I was able to change the root in Unity following the video, but not in VS; so my scripts haven't changed. Do I have to do that manually in this case or is there a faster way?

    @brockormond4131@brockormond41314 жыл бұрын
  • Great video. Wish that C# had an access modifier that allow you to restrict to current namespace and child namespaces. It would allow me to be much more distinct about where domain entity boundaries were.

    @RobLang@RobLang4 жыл бұрын
    • It has something like that for assemblies

      @bbrainstormer2036@bbrainstormer20363 ай бұрын
    • @@bbrainstormer2036 absolutely - however the issue with separating assemblies is you can quickly get into circular reference issues. I want more granular control within a given assembly.

      @RobLang@RobLang3 ай бұрын
  • Much better than Netflix

    @paulopatine@paulopatine4 жыл бұрын
  • Thanks a lot man!

    @yousefabodeif5677@yousefabodeif56774 жыл бұрын
  • Tego właśnie szukałem :p

    @GallVinera@GallVinera Жыл бұрын
  • Thanks!

    @daffertube@daffertube Жыл бұрын
  • well explained

    @sufianahmad7337@sufianahmad73373 жыл бұрын
  • in case anyone finds this, in order to do what he did in 4:01 you hold ctrl and click the files, this also works with highlighting text, and holding shift has a different yet useful effect.

    @tam4655@tam4655 Жыл бұрын
  • You are a pair of chads, thank you so much

    @UNIQUERAGE1@UNIQUERAGE13 жыл бұрын
  • Hey m8. Just dropping in to say that I found you because of one of your ads. So, you at least got someone out of it.

    @relixgames9425@relixgames94254 жыл бұрын
    • Thanks for dropping by. I’m glad to hear those ads are a working lol Enjoy the content!

      @InfallibleCode@InfallibleCode4 жыл бұрын
  • Which code editor do you have in use?

    @artohaapanen7764@artohaapanen77643 жыл бұрын
  • Amazing

    @pcbuilderindia4104@pcbuilderindia41042 жыл бұрын
  • hi , I recently follow another project with Unity 2019.4.1f1. I'm trying to add a script component but it can't be applied because it has a namespace therefore the file name doesn't match to the class name . I've tried to resharper/refactor it and adjust namespace but there is no those options in my visual studio 2017. I was wondering if you could give me a suggestion for this problem (or anyone has a solution ). I will be grateful .

    @lokiorphen@lokiorphen3 жыл бұрын
  • so now instead of interactables namespace you have to use core namespace in the key class right ?

    @farianderson168@farianderson168 Жыл бұрын
  • nice to see rider

    @rohitdoestech@rohitdoestech4 жыл бұрын
  • I always asking why should I use namespaces, here's 2 awesome dudes tell me about the answers. Really nice approach to tell people what namespaces is... Thanks

    @richnaisanze@richnaisanze4 жыл бұрын
  • What a roleplay hahah

    @Bylem_@Bylem_4 жыл бұрын
  • i noticed you use rider, maybe we could get a video on why you prefer it over VS?

    @dynasticc@dynasticc3 жыл бұрын
    • at the very least, I'd like to know if there is an equivalent shortcut to "refactor this" in VS?

      @midniteoilsoftware@midniteoilsoftware2 жыл бұрын
  • I'm new to unity so after the root Namespace how did you access that window

    @albertnelson6967@albertnelson69676 ай бұрын
  • thank u very good video

    @cuttlas2955@cuttlas29554 жыл бұрын
  • does this work in vscode as well?

    @happybadger2270@happybadger2270 Жыл бұрын
  • I got 600 classes and I'm halfway through the project :D

    @Tymon0000@Tymon00002 жыл бұрын
  • I love how these are setup. I can follow along and listen as its explained to the reasoning why these are done the way they are. Keep up the awesome work man. Also just a heads up in your Information panel under your favorite assets you have a link reflecting the same page as another. Editor Console Pro's link is directing to the page for Rainbow Folders 2.

    @unorthodocs1103@unorthodocs11034 жыл бұрын
  • do you NEED to separate then by a folder? no right?

    @dfghj241@dfghj241 Жыл бұрын
  • How to skip "Scripts" or "Assets" names when automatically switching namespaces?

    @Tymon0000@Tymon00002 жыл бұрын
  • Hello there. What if i simply want to call function from another in this "Name space using script" ??? Help me

    @unitygamedeveoper009@unitygamedeveoper0092 жыл бұрын
  • And you can switch Namespace provider option in Folder Properties to tweak automatic namespace refactoring.

    @user-rm2gh2gc5f@user-rm2gh2gc5f2 жыл бұрын
  • you used Chris Heria music?

    @diplodocus3@diplodocus34 жыл бұрын
  • haha, great one!

    @diplodocus3@diplodocus34 жыл бұрын
  • On the right-click menu I don't see the "Refactor This" button, am I missing something? Maybe an extension to download?

    @ofiryehudar12@ofiryehudar12 Жыл бұрын
    • is a extention called rider, from resharper

      @greencubegames@greencubegames Жыл бұрын
  • Does the Core folder have namepace InfallibleCode.Core? Doesn't this produce the same problem?

    @chrisball249@chrisball2493 жыл бұрын
    • I think the answer is at least the two namespaces interactables and keypad are separate now so you can have separate assemblies for each and changing one namespace wouldn't need the other to recompile, that's the benefit. of course changing the core namespace would need the other two both to recompile cause they should reference to it but the overall compile time will be reduced and the readability of the code will be increased.

      @farianderson168@farianderson168 Жыл бұрын
  • Came for the code, stayed for the plot

    @TectonicPlate@TectonicPlate4 жыл бұрын
  • i need to know the end card music

    @Inf4mousKidGames@Inf4mousKidGames2 жыл бұрын
  • The C# Assembly is not showing up in my Solution window... where is it?

    @brockormond4131@brockormond41314 жыл бұрын
  • How about visual studio 2022?

    @restushlogic5794@restushlogic579411 ай бұрын
  • 📦 Download the code at www.patreon.com/posts/36164698

    @InfallibleCode@InfallibleCode4 жыл бұрын
  • Hmm for some reason the project properties doesn't appear. It just refreshes an empty properties window. I'm using visual studio 2022

    @lonelycrescendo@lonelycrescendo2 жыл бұрын
  • adjust namescapes creates namespace like _Project.Scripts.FolderName.SubFolderName :(

    @alpercaner2923@alpercaner29233 жыл бұрын
    • They show how to solve your problem in this video: kzhead.info/sun/o8qiirqMe5qNrIU/bejne.html

      @WillyanSchultzDworak@WillyanSchultzDworak3 жыл бұрын
  • very interesting video. so.. um.. what's a namespace?

    @okamichamploo@okamichamploo3 жыл бұрын
  • Was there a video talking about why we want all of the unity scripts in a defined root namespace? Isn't the whole point of namespaces so you can access the definitions easily.... Why would you need to do that for a Unity project? (He just says "charles told me to do that so all my code can live under the same namespace"). I get the setup bit is so that new scripts created automatically start with that root namespace, but why do I even need one???!

    @MsSnoozable@MsSnoozable3 жыл бұрын
  • this video reminds me of those very very old english learning videos for non English speakers, this role play thing hahahahaha

    @pansammi2184@pansammi21842 жыл бұрын
  • Jason looks like your bro.. :)

    @diliupg@diliupg4 жыл бұрын
  • Thanks for your top-quality videos. But I wonder why your videos have so few likes. This is not their right.

    @ebrahimkarimi1388@ebrahimkarimi13882 жыл бұрын
  • I tried to view the properties on the assembly and it doesnt do anything. And it wont let me right click refactoring of namespaces the option isnt there. What do I need to do?

    @InProductionsrodLove@InProductionsrodLove4 жыл бұрын
    • It's only available in the Rider IDE or if you have ReSharper installed in Visual Studio. It would've been nice if they had mentioned that this functionality required Rider or ReSharper, and that neither option is free.

      @chrisrush841@chrisrush8414 жыл бұрын
  • what code editor is this?

    @darkdoom907@darkdoom907 Жыл бұрын
    • Apparently is Jetbrains Rider, and has not free version :(

      @RintarouOkabe9@RintarouOkabe9 Жыл бұрын
    • @@RintarouOkabe9 thanks kyouma kun

      @darkdoom907@darkdoom907 Жыл бұрын
  • I saw this video and a few others of yours. then i started my project. But now i want to add other folders and i cant. Whenever i try to add a new folder and C#-Files in it they are not recognized in Rider. No intelisence, nothing. So i am back to square one needing to put every new file in one of my existing folders. So in the bottom line this made everything kind of worse. Irewatched this videosand others with thisd topic again and again but i did not find my error. And this is kind of ... not good.

    @Holzf43ller@Holzf43ller3 жыл бұрын
  • Oh hi Mark.

    @anlumman3897@anlumman38973 жыл бұрын
  • do you do this bad casting intentionally?

    @omerfarukbykl6097@omerfarukbykl60973 жыл бұрын
  • Has Jason made a KZhead channel yet??

    @troshto@troshto4 жыл бұрын
  • No entendí nada pero está muy bien

    @hamsoft23@hamsoft232 жыл бұрын
  • So this requrires Rider/Resharper? I think Resharper is 139.00 USD for individuals...

    @Blu3W4r10Ck@Blu3W4r10Ck Жыл бұрын
  • I wish I would've known.. I'm using folders but I have 63 scripts now and it's taking like 3 minutes to recompile between every script change. >.

    @lonelycrescendo@lonelycrescendo2 жыл бұрын
  • Why is his right click and my right click so different?

    @darkdoom907@darkdoom907 Жыл бұрын
  • By moving class files outside of Unity, doesn't Unity recreate the meta files and assign new Guids? Any moved Component class would appear as a "missing script" in Unity. Or is Rider smart about this and relocate the meta files as well? *_UPDATE:_*_ Rider is smart about this!_

    @creepyDeadBoy@creepyDeadBoy4 жыл бұрын
    • I just tested moving and renaming a script in Rider, and it looks like the meta file is relocated/renamed as well. Most importantly, the Guid is retained. _This is pretty slick!_ I don't believe Visual Studio does this. It certainly didn't in the past. After being burned a few times, I got into the habit of always moving and renaming scripts _inside_ Unity to avoid broken references due to new Guid assignments. *From the Unity manual*, "Important: .meta files must match and stay with their respective Asset files. If you move or rename an asset within Unity’s own Project window, Unity will also automatically move or rename the corresponding .meta file. If you move or rename an asset outside of Unity (i.e. in Windows Explorer, or Finder on the Mac), you must move or rename the .meta file to match. If an asset loses its meta file (for example, if you moved or renamed the asset outside of Unity, without moving/renaming the corresponding .meta file), any reference to that asset will be broken. Unity would generate a new .meta file for the moved/renamed asset as if it were a brand new asset, and delete the old “orphaned” .meta file."

      @creepyDeadBoy@creepyDeadBoy4 жыл бұрын
  • hmm, shouldn't Doors and Keys also be in Interactables? As in InfallibleCode.Interactables.Doors and InfallibleCode.Interactables.Keys ??

    @BDtetra@BDtetra3 жыл бұрын
  • I appear to have some namespace issue in my project, but this video didn't really teach me what they are. I like the format though, it's basically artist me and my programmer friend.

    @Visuwyg@Visuwyg2 жыл бұрын
  • Does a minor mistake: *OOF*

    @paulogodinho3275@paulogodinho32754 жыл бұрын
  • reminds me of mod ash

    @LostSockDrawer@LostSockDrawer Жыл бұрын
  • Meanwhile, in the real world.... This falling into the same problem as Brackys videos

    @Ziplock9000@Ziplock900010 ай бұрын
  • I had a code smell once

    @UnityVR@UnityVR3 жыл бұрын
  • Film noir

    @nauka9634@nauka96342 жыл бұрын
  • ..and this is how you never finishe your game project 😂

    @fille.imgnry@fille.imgnryАй бұрын
  • too much grammer not beginner friendly

    @toystoryscarymovie-forkids3323@toystoryscarymovie-forkids3323 Жыл бұрын
    • not everything has to be beginner friendly :) It was perfect for me^^

      @lotussy7698@lotussy7698 Жыл бұрын
  • It's a bit cringe

    @INeatFreak@INeatFreak4 жыл бұрын
    • Let’s be honest - it’s a LOT of cringe lmao but I had fun making it and people seem to like them!

      @InfallibleCode@InfallibleCode4 жыл бұрын
    • ​@@InfallibleCode No! this is, by far, the most in depth tutorials i have found on youtube. Most people just slap a huge monolithic class and say , "congrats! you made a game! Game dev is easy! Go make your own game." Its easy to make tutorials with buzzwords and click bait titles for views. You, on the other hand, showed me how to future proof and create scale-able code. Yes, it looks cringe and stupid but it works , so, its not cringe and stupid. You choose to support developers that were on the verge of insanity because they didnt know how or why their code failed. I dont care if you upload 2 hours long videos of you talking to your self. Your Tutorials are DEADLY. Every time my project grew in size and complexity and the frame rate "Tanked" like Tiananmen square, You were there to tell me not to be afraid. You and your Schizophrenia kept me from quitting all together. Calling ​Infallible Code cringe is like calling Mother Tereza cringe because she fed the poor and helped those in need... All that you say, you are helping people. A lot! that can never be "cringe" in my books. Ps Sorry if my comment is a bit incoherent but i haven't slept for 30+ hours.

      @alexmobile5547@alexmobile55473 жыл бұрын
KZhead