Search Unity

Is there a way to allow coding in C++ instead of C#?

Discussion in 'Getting Started' started by Vintire, Jul 1, 2020.

  1. Vintire

    Vintire

    Joined:
    Feb 12, 2019
    Posts:
    1
    I really want to learn C++ because I think I could use it more in the real game development business. Are there any plugins?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    Ah C# the language that is not used in real game development ;)
    If you are just starting to learn to program then I would strongly urge you not to learn C++ with Unity. Unity is focused on C#, you can use C++ but the process is not as simple and much less user friendly.
    Learn C#, it will teach you a lot of the same skills which can then be transferred over to C++ once you are comfortable.
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    Wishful thinking. Game engine development is C++ but actual game development is rapidly shifting away from C++. Unity isn't the only game engine to use C# and the others that don't have it have languages like Python, Lua, etc.

    Unreal 4 is one of the few engines out there that allows you to code the game itself in C++, but Epic Games has stated that they have been considering an alternative language (though they don't know the form it will take) to make life easier.
     
    Last edited: Jul 2, 2020
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Hmm... perhaps I should point out MiniScript to them. :)
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If you really want C++, use Unreal Engine instead.

    In Unity, the engine itself is primarily in C++. Your scripts are in C#. If you select to compile using IL2CPP, your C# scripts are compiled to IL, which is then converted to C++, and finally to machine code similar to any other C++ application. So the benefits of writing your scripts in C++ are fairly limited, while the downsides of C++ are all still there.
     
  7. IrrisWhatts

    IrrisWhatts

    Joined:
    Aug 17, 2020
    Posts:
    16
    I recommend using C# as it is more friendly with Unity. Of course, you could use it but it won't be so effective.
     
  8. asherdavidson

    asherdavidson

    Joined:
    Aug 17, 2020
    Posts:
    17
  9. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Unity scripting is C# only. You can write native plug-ins in C++, but they are mostly intended to provide functions that can be called from the C# side. Plug-ins can also be used for low level rendering, by accessing the platform's graphics API directly.

    You *can* write game logic in C++, but without easy access to the objects and components on the C# side you'll be be quite limited. Iteration will also be *much* slower, because Unity doesn't reload native DLLs (AFAIK you need to close and re-open the editor).

    As posted before, if you want to practice writing games in C++, use an engine where C++ is supported for such thing, like Unreal and Godot.

    Refusing to learn C++ means you're forever dependent on others to provide plug-ins for functions that aren't native to Unity. You won't be able to make heads or tails of your game's crash dumps (because your C# is ultimately converted to C++ and that's what the dumps will reference). You will also have a harder time getting into the big AAA studios if that's what you're aspiring for.

    There's nothing wrong with it, but I believe a game programmer should become able to deal with multiple programming languages if they want to make an actual career out of it. You don't really have to master them all, there's no shame in keeping some websites with references handy to check how things are done in X, Y, or Z. Unless you really limit yourself to releasing Unity games for PC for Steam (where you can still get away with Mono builds), you will have to deal with languages other than C# eventually.
     
    Last edited: Aug 19, 2020
  10. VisionizeTech

    VisionizeTech

    Joined:
    Mar 4, 2020
    Posts:
    5
    What are your thoughts on a "Do-it-All" kind of person who unfortunately only had a few computing (Java) in Engineering course but can teach myself most things if properly explained. I wonder if you'd recommend a series of languages that "flow" better. I have a very capable computer and series x xbox with dev mode. I want to expand from other industries into game dev with real quality story on point with gameplay type avenues. And as a single dad i am using unity because until you make $100,000 it's free. But I've Also Made some scripts in C# and am somewhat familiar with at minimum basic follow scripts for say camera but the core of this missing. i am dedicated i just hope you may know of a preferable path i don't want to learn 1, i want to learn multiple because some aren't as "futer-Proofed."

    I hear python is great for beginners but am just looking for if say starting C# into C++ would be less of a "flow" of transferring that intuitive code feel. or say another like Python or Something Else then others if it is relevant and thank you.
    Tom
     
  11. VisionizeTech

    VisionizeTech

    Joined:
    Mar 4, 2020
    Posts:
    5
    Hi I don't mean to be a bother but you sound well versed and i'm a very saavy beginner but beginner nonetheless and working on a big project that will take time i know but you referred to multiple language knowledge which was my plan because you never want to get stumped because you didn't learn at least "this" from "that" language. What main ones would you recommend particularly for someone who wants to be basically at the level you seem to be full industry knowledge tells me i must be able to be versatile but any order? would it be bad to say do python for simplicity before something or maybe after another etc? Thanks so much
     
  12. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Not that you asked me, @tsegreti, but I say stop worrying about what the right path is and just start going down one. You'll lose far more with your indecision than by making a wrong decision.
     
    Ryiah, JoeStrout and karl_jones like this.
  13. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    All of us having been beginners at one point we understand the feeling of wanting to choose "correct" languages rather than spend time learning languages that ultimately end up being irrelevant, but that way of thinking is itself incorrect. You should choose your language based off of your needs at this moment.

    Do you want to learn Unity? Choose C#. Do you want to learn Unreal? Choose C++. Learning that first language can be daunting and it can take months to do so, but each additional language after that will take far less time than the previous and at some point you will find yourself picking up new languages within the time span of a single week.
     
  14. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    C++ and C# are about as similar as two programming languages really get. I learned the basics of C++ first (primarily because C# didn't exist yet), and it made learning C# really easy. You're not wasting your time choosing either.
     
    Lurking-Ninja likes this.
  15. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    Your first few years of writing C# will yield poor code that works.
    Your first few years of writing C++ will yield poor code that randomly crashes.

    Writing "good", readable, efficient code takes experience on either.
    Pretty much any other language is more forgiving than C++. Imho, the fastest way to game development is learning C#, Java, Python, or any other language that does not require you to actually understand what's happening under the hood just to be able to write correct code.

    If you're willing to put in more time and effort, start with C++. After a couple years moving to any other language will be a piece of cake.

    My opinion on this: want to learn quick? go for C#. want to learn properly? go for C++. You can use both in Unity, though C++ takes a great deal more effort.

    No matter what you end up learning, it will be useful. Most programming skills can be easily transferred across languages.
     
    Last edited: Apr 27, 2021
    Joe-Censored likes this.
  16. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    While that's one way to view it the other is that C++ forces you to remove the training wheels compared to other languages and by doing so forces you to become a more competent programmer when you otherwise might have held onto the training wheels.

    I remember working for a company where the daily software app we worked with had been developed by a third party that had never taken off their training wheels. To say that it was bug-ridden wasn't doing it justice. If you entered anything wrong it caused the server to crash and have to be restarted.

    In my opinion if your end goal is to become a programmer you shouldn't be afraid of choosing a language that forces you to write your code properly. That's not to say that you can't choose an alternative but choosing one that doesn't force you to remove the training wheels only works if you're motivated to remove them on your own.

    That said you can always choose to learn C++ after you've picked up C#. I picked up QuickBASIC before I picked up C++ and it didn't make me a less competent programmer for it. Though I had to unlearn a handful of weird practices I would have had to do that with any language.
     
    Last edited: Apr 28, 2021
  17. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    If you want to learn C++, it's better, in my experience, to do it by working with an existing C++ codebase where you are making changes and adding features.

    This way you are surrounded by examples of how things should be done and there's less room for error.
     
  18. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    Agreed. That's what I meant by "want to learn quick? go for C#. want to learn properly? go for C++", but you articulated the idea much better :)

    Maybe all OP wants is to get results fast, as that can be encouraging for many people. Many basic concepts that are more easily understood in C# (or other languages) can later be transferred to C++. Deep insight into how things work can often wait until the basics are in place.

    It really depends on how he learns, everyone has a different learning process. Some prefer to use training wheels until they feel more secure, some prefer to speed down a hill towards a crocodile-infested river and get chewed to death time and time again (that would be me).
     
    Last edited: Apr 28, 2021