Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Which version of C# and .NET necessary for Unity (now and in the future)?

Discussion in 'General Discussion' started by nickicool, Aug 14, 2022.

Thread Status:
Not open for further replies.
  1. nickicool

    nickicool

    Joined:
    Jan 19, 2022
    Posts:
    11
    I'm new to C#. Help me figure out what kind of knowledge stack I need to program for Unity (game for my self, just like hobby)!

    1, Design patterns will be recomended - I understand that.
    2. Which version of the C# language should I rely on when learning (right now and in the future)? In one of the neighboring topics, I read that Unity will soon support C#7.0 (this right?).
    3. And what about the platform .NET? As far as I know it is currently being used .NET 2.0. Did I understand this correctly?
    4. When will C#7 support be added, which version of .NET will be relevant for Unity?
    5. Will it be used .NET Core?
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    It seems you have not done even a cursory google search on these things first?

    For example C# 7 is and has been in unity for some time. You also are incorrect, its .NET standard 2.0, not .NET 2.0. VERY different things.

    I recommend actually searching these things first, its super easy to find the answer to all of these both on the forums here using the search function, and via google.
     
    Ryiah and nickicool like this.
  3. nickicool

    nickicool

    Joined:
    Jan 19, 2022
    Posts:
    11
    I'm sorry, but you're wrong! Honestly! I tried Googling, but I didn't get the result that I wanted. I just got confused and that's it! Yes, I found this page https://docs.unity3d.com/2021.3/Documentation/Manual/CSharpCompiler.html right now and now I know that there is support for C#9 (with some caveats). But everything that concerns .NET - I don't understand, I'm confused about them. I'm sorry, but I repeat - I'm new to C#. And technology .NET a whole bunch! I was thinking of defining the technology stack, what exactly needs to be taught for Unity programming, and buying a book. I don't want to programming enterprise applications, or backend for sites, or windows applications - only code for logic in Unity games (for me, like hobby).

    The most frequently recommended book for C# beginners is "Andrew Troelsen". In my country there is a translation of several editions of this author: "Pro C# 9 with .NET 5: Foundational Principles and Practices in Programming 10th ed. Edition" and "Pro C# 7: With .NET and .NET Core 8th ed. Edition". The 8th edition I could buy in "second-hand" store, which of course is more profitable for me (if there is nothing important for Unity programming in the new10th edition).

    Perhaps these books are not quite suitable for my purposes... I do not know if I will need the ASP.NET Core, Entity Framework Core, or .NET5 features described in these books. That's why I'm asking for help. Perhaps there are more suitable books...
     
  4. Gotmachine

    Gotmachine

    Joined:
    Sep 26, 2019
    Posts:
    34
    Since version 2021.3, Unity fully supports .NET Standard 2.1 and C# 8.0, and has partial support for C# 9.0.
    In terms of API surface, .NET Standard 2.1 can be summarized as being equivalent as .NET Framework 4.8 + a few extras, somewhat comparable to .NET Core 3 but much less extensive than .NET 5+. Ultimately this doesn't really matter, as in the context of Unity you will be using only a tiny fraction of the .NET API surface, and most of that hasn't changed significantly between versions.

    Short-mid term, there are no major planned evolution beside more complete support of C# 9.0. Long term (~3/5 years), it is expected that the whole Unity ecosystem will switch away from Mono/.NET Standard to modern .NET 6+.

    As for learning C#/.NET for Unity, my recommendation is don't. Start using Unity and learn it on the fly. Just stay curious and document yourself. There are plenty of online resources for all the tiny questions you will have (StackOverflow is great for that).

    Those books can be nice to have as references for low level stuff and basic language concepts, but in terms of applications they will be mostly about things that are irrelevant or even undesirable in the context of game development.
     
  5. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,677
    A conceptual hint: In Unity you work with the Unity API which is designed to be platform-independent. The NET Api focuses on interactions with the OS, namely Windows.
    There are of course platform-independent language constructs that came with the varying versions of C#, but those are usually not very relevant to beginners and even intermediate users.
     
    nickicool likes this.
  6. Gotmachine

    Gotmachine

    Joined:
    Sep 26, 2019
    Posts:
    34
    That's almost entirely false. Even in the Windows-only .NET Framework, almost the whole API surface is platform agnostic. And modern .NET has been platform agnostic since 6-7 years.

    But as an extra to the OP question, because the evolution of .NET and how Unity fits in that is indeed confusing, here is a quick summary :

    The first thing to understand is that there are 3 main components to the .NET ecosystem :
    - The programming language that gets compiled in the IL (Intermediate Language) code. For example, C#, F# or VB.NET
    - The BCL (Base Class Library) : this is the "standard" API available to use though the C# language. This is where all the base building blocks are defined, for example stuff like int, string, List, Array...
    - The JIT runtime (also referred as the CLR) : this is the execution engine, the thing that execute the IL code on your computer.

    Things started with the .NET Framework about 20 years ago. The .NET Framework was initially a Windows only Microsoft product, which lead to an independent initiative to re-implement a cross-platform version of it, this is the Mono project.

    For a long time, up to ~2015, both product evolved separately, with Mono providing compatibility for newer C# / .NET Framework versions :
    - A re-implementation of the BCL where the various APIs were made to work on other OSes and platforms than Windows.
    - A JIT runtime to run the IL code on other OSes and platforms than Windows.

    Somewhere in that timeframe, Unity decides it want to integrate C# as a scripting engine and starts using Mono for that, a logical choice because of the multiplatform goals of Unity.

    Then things got a bit complicated. Microsoft decided to make its own cross-platform version of the .NET framework. This was named .NET Core. While this new product started evolving, the windows-only .NET Framework continued to be a separate product, and Mono too.

    There was now 3 separate products for the same ecosystem, which lead to the creation of .NET Standard, a standardization of the cross-platform BCL APIs that all products should cover. This was essential because the .NET ecosystem heavily relies on a huge collection of libraries (ie, additional APIs provided by various people). Without that standardization, all those libraries would have required separate versions for each of the 3 products. That's how we got .NET Standard 1.0, which was implemented by .NET Framework 4.5, .Net Core 1.0 and Mono.

    Around 2015, Mono is bought by Microsoft which fully open source it, the .NET Foundation is founded, and most .NET things owned by Microsoft are put under its umbrella and fully open-sourced. Over time, focus is shifted towards .NET Core, which rapidly becomes a much more stable and mature product than the two others. In 2020, .NET Core is renamed to just .NET with the introduction of .NET 5.

    As of now .NET Framework is essentially abandoned, and Mono is slowly becoming less and less relevant because it's main point was cross-platform compatibility, which is now provided by the main .NET product, and because it's lagging behind in terms of features and performance. In that context, Unity has announced that it is working toward moving away from Mono.
     
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    You don't need to worry about most of this. At the entry level Unity just handles it for you, and you don't have to worry about it at all until you get to some pretty "advanced" (in the specific context of Unity) uses. In some cases, such as deploying to mobile devices, you'll need to configure things in a particular way, which you can almost always do by following the relevant instructions.

    In short: you don't have to worry about your "stack", and concern with it seems to be wasting your time.

    To allay potential concern there, the "stack" Unity is built on has changed fairly significantly since ~2009 when I started using it, but the code I wrote back then would almost certainly run if I dropped it into a current copy of Unity and attached it to objects. The fundamentals of writing code simply haven't changed.

    - - -

    What you do need is to learn those fundamentals. While it's not Unity specific, if you want to learn C# I'm going to go ahead with my standard recommendation of Rob Miles's C# Yellow Book, of which the online version is free. There are also translations available, fingers crossed there's one in your language. It's not perfect, but as far as I know nothing is.

    It is not Unity specific, but it's also not enterprise specific or whatever. There are a few typical C# programming things which aren't "best practice" in Unity, but you can safely ignore that until you're confident writing code. It's something you can easily learn and start to apply later, and change out in old scripts if/when it matters.

    The important thing is that it teaches the fundamentals of programming, i.e. providing instructions for a computer to follow in order to solve some problem. Many rookie game programmers try to skip this step and go straight to learning "just the game programming stuff". The catch is that game programming isn't a subset of programming, it's a specialisation. You're best off learning the fundamentals and then building on them rather than trying to skip stuff.

    - - -

    You will need to combine something like Yellow Book with the content at the Unity Learn site. Knowing how to use the Unity API* and how to attach Components to GameObjects and work with them in the Editor is some Unity-specific additional knowledge you'll need to pick up.

    There's nothing wrong with playing around with these before you're up to speed on your programming fundamentals. Go ahead and do stuff in whatever order you want. My advice is simply to not forget about / skip over filling in the fundamentals at some point.

    Also, you'll never stop learning. I've been doing this for well over a decade and many projects still involve me doing research or learning new stuff for one or two parts. Programming and game dev are vast and expanding areas of study. Even if you somehow learned it all, in a week there'd be more. So don't worry about that. Just learn what you need to get a job done, and explore what you need when you need it.
     
    Ymmersive, Wattosan, NotaNaN and 5 others like this.
  8. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    Side fun fact - rob miles was my lecturer at university :) Its so funny to see the yellow book that we all assumed was just for us, being used by all sorts of people around the world years later :D
     
    bn-l, Ryiah and angrypenguin like this.
  9. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,508
    Agreed!

    Also: Penguins are cool. Literally. :D
     
  10. retrobrain_dongyi_cai

    retrobrain_dongyi_cai

    Joined:
    Feb 3, 2021
    Posts:
    10
    My suggestion: You need to learn both Unity stuff and C# stuff, but you should prioritise in learning C#

    Unity is indeed behind C# official releases, and many Unity tutorials or codes are not exactly best practices for programming in general. Learning basic C# stuff can help you coding in Unity. And learning Unity stuff will help you optimize performance.

    To your questions specifically:

    1, "Design patterns will be recommended", I persontally don't recommend design patterns, some patterns are over-engineering to me, and some of them even make performance worse. If you're still learning it instead of doing big stuff, just do whatever you want to do, and learn during progress. Otherwise, find a suitable pattern for your project, don't constrain yourself by the design patterns. I know some people will disagree, but in Unity world, I believe performance and productivity should come first before design pattern.
    2. There is only one C# language, it's called C#. higher version brings more language feature to it, but it doesn't mean you can't write code with the old way. Many C# tutorials don't cover brand new features, so just "learn C#" and that's it.
    3. In Unity, it's as simple as .NET Standard 2.0 or 2.1. In other world of .NET, you should target .NET Standard 2.0 for base library and .NET 6 for whatever thing you want to do (asp.net, WPF, maui, etc)
     
    nickicool likes this.
  11. nickicool

    nickicool

    Joined:
    Jan 19, 2022
    Posts:
    11
    Exactly!!! This is exactly the reason why I couldn't figure out how to study C# in the context of Unity and the whole zoo.NET technologies! Thank you for the short and at the same time detailed explanation!

    And big thanks all answers for your help me! I will study the fundamental knowledge of C# and practice it with solving problems in Unity! Step by step!
     
  12. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,967
    If you want a nice way to get introduced to all these concepts without getting bogged down with too many details, and still getting some actual gamedev done, I cannot recommend this enough: https://learn.unity.com/course/create-with-code

    Its easily the best introduction to unity available out there, and will get you to a point where you know enough about how to code within unity to get stuff done and to continue your learning from there in a more applied way (i.e. trying to learn solutions to specific problems you are trying to solve in your project, rather than just learning theory constantly that you may or may not ever use)

    It will also leave you at a point where you could progress onto one of the programming certification courses next to get an actual qualification, if you wanted to :)

    Good luck :)
     
    Last edited: Aug 15, 2022
    NotaNaN, nickicool, spiney199 and 2 others like this.
  13. nickicool

    nickicool

    Joined:
    Jan 19, 2022
    Posts:
    11
    Thank you! :)
     
    MadeFromPolygons likes this.
  14. unity_Q6gtYM13wT7GjQ

    unity_Q6gtYM13wT7GjQ

    Joined:
    Oct 1, 2021
    Posts:
    3
    Another great book is The C# Player's guide by R. B. Whitaker. It is gamified so it's more enjoyable, at least from my POV.
     
  15. Tiritto

    Tiritto

    Joined:
    Apr 19, 2019
    Posts:
    2
    And here I am, finding this thread under literal first result of my Google Search.
    Congratulations, you've officially became this guy on the internet.
     
    BPRICE and DragonCoder like this.
  16. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,943
    Well there's your problem. ChatGPT is the way the cool kids do it now. :p

    upload_2023-3-4_5-36-23.png

    Joking aside here are links to the reference manual that has the actual information in it. It's best to start there as Google will frequently direct you to a link that is no longer accurate. Like this thread. ChatGPT is frequently more helpful in my experience too though it can be incorrect on occasion so be careful if you're relying solely on it.

    https://docs.unity3d.com/Manual/overview-of-dot-net-in-unity.html
    https://docs.unity3d.com/Manual/CSharpCompiler.html
     
    Last edited: Mar 4, 2023
    CodeSmile and MadeFromPolygons like this.
  17. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,553
    I have no idea who the heck "this guy" is, but the first hit for "C# unity version" is this page:
    https://docs.unity3d.com/Manual/CSharpCompiler.html

    So, yeah, you have to use google search.
     
    MadeFromPolygons likes this.
Thread Status:
Not open for further replies.