Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Detailed knowledge of C# required?

Discussion in 'General Discussion' started by rmb303, Oct 19, 2017.

  1. rmb303

    rmb303

    Joined:
    Jan 6, 2016
    Posts:
    19
    Hi,

    I was just wondering how much detailed knowledge of C# was really required to make a fully working game.

    As a background, I learnt a little Basic back in the 80s on the Commodore 64, ZX Spectrum,and later the Amiga. I then learnt the basics of C about a decade later; never got round to doing anything with it, but understood the basic syntax.
    In the early 2000s, I learnt enough Java to do some simple windowed programs, but nothing too complex.
    Now, I'm having another go at programming games, and Unity makes it seem simpler than it ever has to me.

    I've followed many tutorials on using Unity, and read quite a few books on C#, but my question is:

    "How much detailed knowledge of C# do I really need to make the games I want to make - mainly procedurally generated 2D games, both top down and side view?"

    The syntax is very similar to Java (and C really), so I understand the basics of classes, methods, flow, variables, etc, but I'm having a little trouble grasping (to me) vague concepts like abstract classes, delegates, anonymous types and methods, lambda expressions, extension methods, and more.

    Do I really need to understand this stuff to make a good game, or when I need to know such things, will it become obvious and easier to learn at that point?
    Will these things just make more complex game structures easier to expand, while being possible to get by without them?

    Thanks for any help for an over-anxious, probably too old to start learning once again, wannabe games coder.
     
  2. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,552
    You can get by without them. I've made tons of Unity games and have never used an anonymous type, and lambdas scare me. Abstract classes are basic and just give some help in certain situations, but not required.

    Learning the Unity API and understanding the component system will be the most important thing to get comfortable with. Then being comfortable adding and multiplying with Vector2/Vector3's.
     
  3. mysticfall

    mysticfall

    Joined:
    Aug 9, 2016
    Posts:
    649
    Generally speaking, knowing a programming language deeper (i.e. learn how to use advanced features like lambda, or become proficient in design patterns) doesn't allow you to do something you couldn't before.

    Rather, it usually makes you do it in a manner more efficient, easier to extend or modify.
     
    TonyLi, RavenOfCode, JohnnyA and 6 others like this.
  4. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
  5. Deleted User

    Deleted User

    Guest

    A lot of it's easier than you think, hit up Unity learn as they have a video section of all of these and they provide very simple answers.. Like a delegate is pretty much a function that can be passed around and used like a variable.

    Can't say I ever, if hardly use abstract classes, I do often use quite a bit of stuff you don't have on there though.. Co-routines, switch cases, singletons, Dictionary lists, Enum's, Polymorphism, overloaded methods, etc.

    https://unity3d.com/learn/tutorials/s/scripting

    When it comes to Lambda expressions it really depends on what you're doing as to whether you want it, like in an RPG with SQL lite / Linq Lambda's make sense. It's essentially an anonymous function used to create delegates or expression trees.

    It's all about passing arguments as functions or returning function calls. I'll not get into the "where" statements etc. you can search engine that.

    But in short Lambda is supposed to be a more efficient way of writing anonymous delegates, now you could just write a function but it's a pain (or long winded) when trying to convert SQL to LINQ objects. Anon's / Lambda's they give the benefit of "closures" which allows you to pass the local state to a function without having to add additional parameters in certain cases.

    It's like a layer of abstraction really, make things simpler / easier to read and use..
     
    Last edited by a moderator: Oct 19, 2017
    Ryiah likes this.
  6. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    13,087
    Pretty much.

    It sounds like you understand the fundamentals that'll get you making stuff that works, and I was getting stuff done well enough with a similar level of knowledge. In my mind, as long as you take the time to learn from what you're doing - identify where stuff was tricky or painful and thinking about better approaches - then you're moving the right way and should be pretty happy. And when you're doing that, yes, you'll eventually start to understand where the advanced stuff you mentioned fits and how it helps.
     
  7. AdamAlexander

    AdamAlexander

    Joined:
    Jul 24, 2015
    Posts:
    61
    Most of the time you only want to use the basic features of C# in Unity anyway. Unity C# runtime uses a pretty badly performing garbage collector which you want to avoid having invoked. A lot of the fancier features in C# such as linq expressions, anonymous functions even foreach loops all allocate memory in Unity, which will eventually invoke the garbage collector. So its preferred to use the simpler language features because they don't allocate any memory.

    I think the new 2017.1 release may have gone some way to reduce these issues, I'm not sure.
     
    Arowx and Martin_H like this.
  8. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,151
    No.
    Yes.

    I think this month I've hit the first case where I ever needed something "abstract". I would suggest to take a look at interfaces though, just so you know what they are and know what to look into if you ever come accross a good usecase for them.
     
    RavenOfCode likes this.
  9. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    2,338
    This was fixed ages ago. I agree on the rest of the post.

    You can do it without really knowing anything about C#, if you know where to find what you need. Google it until it's done, learn in the process. There's plenty of tutorials on Unity game creation, there's even more tutorials on C#.
     
    Martin_H likes this.
  10. wccrawford

    wccrawford

    Joined:
    Sep 30, 2011
    Posts:
    2,038
    My only argument against that is that sometimes the inefficient way is so inefficient that it's effectively impossible. This goes both for CPU Time and maintenance on the code as things break and need to be fixed.
     
    angrypenguin likes this.
  11. GarbageCat

    GarbageCat

    Joined:
    Jul 31, 2012
    Posts:
    228
    avoid lambda expressions and the like much as possible
    if you know the basics you are all set

    the GC in unity is a games killer
     
  12. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    7,526
    Yes and No.

    Yes - Most games can be written in Unity with just basic C# code.

    No - There are language features that you can leverage in your game design to make things easier, this takes learning/practice and trial and error. For instance design patterns are like small gadgets that if learned and used right can make complex problems easier.

    Hint: You know you might need better designed code when your own code start tripping you up and gets too complex, this is when the art of Refactoring your code and it's design and architecture comes into play. Often you can get buy with a divide and conquer approach where you separate your code by what it does (e.g. Unity Components).

    Hint2: Keep track of your games performance with the profiling tools they will get you into the habit of noticing which areas of your code become a performance bottleneck, but don't start optimising too early wait until your game is at least early alpha/beta.
     
    Last edited: Oct 19, 2017
    Ryiah likes this.
  13. KarenLCrawford

    KarenLCrawford

    Joined:
    Oct 18, 2017
    Posts:
    13
    I think learning actual C# was fairly easy, learning all the special Unity goodies is what took more time. If your game runs > 60fps at its´most intensive parts, you are good. I am sure if a professional programmer looked at my work, they would laugh (nested if statements etc), but the game runs smoothly and is finished and I only had one or two major hiccups because of my C# that wasted an hour or two. Most importantly, late in development I never had an issue finding issues.
     
    digiross likes this.
  14. rmb303

    rmb303

    Joined:
    Jan 6, 2016
    Posts:
    19
    Ok, thanks a lot for your help and encouragement everyone!
    I'll keep plodding on with what I currently do know, and will get round to learning the more abstract stuff once it seems like it might be useful.
     
    Martin_H likes this.
  15. peterk1968

    peterk1968

    Joined:
    May 11, 2015
    Posts:
    46
    I don't think you need to be an expert at C#. I did my first large learning project on Unity 3 years ago and I knew no C# at all when I started. You can get answers to your questions pretty easily (as long as you phrase and frame them effectively).

    If you're a good Java programmer, you should have no problem whatsoever. My brain was thinking in Java for the first year, even though it wasn't Java.
     
  16. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    7,526
    PS the trickiest part with Unity is there is not Main or Game Loop you just have to hook into Unity's with Components (Extended MonoBehaviour Classes you make) and their Update() function.

    It can take time to get your head around the components system if you are used to writing your own main loops.
     
    Ryiah and Martin_H like this.
  17. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,479
    you mention you already know C and Java so you will be well on your way. Just applying what you have learned from those 2 languages will get you enough toy start working on a game.

    The concepts you mentioned are not absoluty needed to make a game, and you can learn them as you create your game in Unity. Most of them are pretty simple concepts it just takes some thought to know when and where they are useful. Good things to learn about, but that will come with time and experience in the langauge and framework. I would worry more about learning unity and its api.
     
  18. Quingu

    Quingu

    Joined:
    Jan 30, 2013
    Posts:
    648
    Personally I program in C# similarly to what I would do in C++. This means that I avoid "innovations" like lambda crap, LINQ and other stuff like that.

    You can't go wrong with simplicity. Use simple, direct solutions to your problems and avoid needless complications. Nobody cares about you being "advanced" unless you're looking for a job. Players care only about your results.

    It's definitely important to have a solid grasp of OOP design and knowledge of design patterns.
     
  19. mysticfall

    mysticfall

    Joined:
    Aug 9, 2016
    Posts:
    649
    But... but C++ supports lambda too :p
    I do agree that solid grasp of OOP should be considered more important thing to learn when using languages with such a paradigm.

    But I also believe that there exists some concensus among programmers about what features modern programmming languages should have, which includes support for lambda functions.

    That's why languages of a similar paradigm seemingly evolve into the same direction. For example, Java 9 was released a few months ago with lambda, local variable, optional type, pattern matching support, which are features that other modern languages already support.

    Simplicity is a good thing, but someone can even argue he doesn't need abstract classes or interfaces because he can do everything without OOP. Before one understands such principles like polymorphism, design patterns, OOP looks to be just a 'needless complication'.

    He would think that he can create everything by writing independent 'functions' and for him it would seem like the simplist solution to any problem.

    The same goes for such features like lambda, in my opinion. It's hard to see its benefits before you actually understand and get familiar with them.
     
    Last edited: Oct 22, 2017
    xVergilx, Ryiah and passerbycmc like this.
  20. derf

    derf

    Joined:
    Aug 14, 2011
    Posts:
    349
    Don't hate on Lambda man!

    It has some important uses IF you require them, you will be glad Lambda is waiting on the sidelines looking to get put into the game.
     
unityunity