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

Why does unity support neither C++ nor Java?

Discussion in 'General Discussion' started by MapuHoB, Jan 26, 2015.

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

    MapuHoB

    Joined:
    Aug 17, 2014
    Posts:
    50
    What is the reason that lies below? I somehow don't seem to understand why, especially C++ isn't included in the languages for unity(only Boo, jS and C#), when most of the games are written in C++ and also is estimated to be much more performance- wise in comparison to other languages. What about Java?
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The reason is that they decided to rely on the .net framework or more precisely Mono. In fact you can use any .net language as long as you take care to use the correct .net version which is an outdated one at the moment, but that should be resolved once il2cpp can be used on all the platforms that require aot.
    You can already write plugins in C++, but you can hardly use it to write code that is tightly integrated as the C# code.
     
  3. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Java and C# are very similar with very minor syntax rules. If you're familiar with Java, you shouldn't have a problem adapting to C#.
     
  4. CodeMonke234

    CodeMonke234

    Joined:
    Oct 13, 2010
    Posts:
    181
    unity (the game engine itself) is written in c++.
    the behavior of your game is written in a scripting language, which is run by the engine.
    This approach is very common - for example alot of the early bioware games were written in c++, but the bulk of the behavior was in embedded Lua.
    As another example, consider UE4 which is written in c++ while blueprints is an embedded visual scripting language.

    One reason for this is that it is easier to write and iterate on the behavior code if it is in a scripting language.
     
  5. MapuHoB

    MapuHoB

    Joined:
    Aug 17, 2014
    Posts:
    50
    Should I understand that it's hard or not good idea to add a programming language to a game engine rather than scipting language?
     
  6. CodeMonke234

    CodeMonke234

    Joined:
    Oct 13, 2010
    Posts:
    181
    you can write everything in c++ (if writing your own game, not unity)

    but it is much more time consuming to test behavior code written in c++ because the language is more difficult, and it also requires recompilation.

    Behavior code requires lots of changes when you are iterating on your game design.

    So by leveraging a scripting language for behavior, you are enabling faster iteration because the language is simpler and doesn't require a lengthy compilation step.
     
    theANMATOR2b likes this.
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    The more programming languages you add the more expensive it gets to support, the more you fracture the community. A better question may be "Why does Unity support three languages when they all do exactly the same job?"
     
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,954
    Most game engines may be written in C++, but the games themselves are often implemented on top of those engines in scripting languages. Some very core mechanics may still be implemented in C++, but the vast majority will be in scripts.

    Unity is written in C++ but uses Mono (aka C#, UnityScript, Boo) for scripting.

    Just-in-time compiling has caught up to ahead-of-time compiling and isn't that much different now. Think about it for a moment. A JIT compiler, like Mono primarily uses, is able to take full advantage of every instruction set available on a computer because it compiles when the section of code is needed.

    An AOT compiler, like C++ uses, does not have this advantage. If someone wishes to support every instruction, it has to be compiled once for every single combination of instruction sets. In the past this wasn't a problem when you had only a couple but modern processors have many additional instruction sets.

    Same as with C#. A JIT compiler.
     
    Last edited: Jan 27, 2015
    Deon-Cadme and Dameon_ like this.
  9. MapuHoB

    MapuHoB

    Joined:
    Aug 17, 2014
    Posts:
    50
    Thanks for the explanations. But still a thing I can't understand is why UE4 went from UnrealScript to c++? I read that every programming language can be used as well as an scripting language. Is this the case with UE4? I mean are devs using UE4 using c++ as an scripting lang or like programming?
     
  10. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    For UE4's logic you are probably better off asking on their forums. In essence Unity decided the .NET and Mono frameworks would be best for their scripting. UE decided that C++ would be best.

    Both languages have ups and downs. But ultimately how well you program will matter more then which language you choose.
     
    jjkiii and Dameon_ like this.
  11. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,954
    UnrealScript was replaced by Blueprint. C++ was always an option because neither UnrealScript nor Blueprint are compiled scripting languages. They are interpreted which is significantly slower.

    Any programming or scripting language is capable of being used with another. It may take significant effort though depending on the language. Those that share a common framework, such as Mono, are going to be easier than those that do not.

    Last I checked there was active effort to bring the C# language to UE4 for scripting purposes.
     
    Last edited: Jan 27, 2015
    Deon-Cadme and MapuHoB like this.
  12. Deon-Cadme

    Deon-Cadme

    Joined:
    Sep 10, 2013
    Posts:
    288
    @MapuHoB - Sounds like you want to learn how to make game and got hung up on the engine and language differences... am I right?

    Ignore all of that, there is too many differences for us to cover here and you wouldn't even understand half of it without serious knowledge in different game development topics.

    Yes, C++ is a common language in the games industry but many people grow bald before they figure out how to use some of the features properly. C++ is typically used to write the game engine but a simpler language is usually added on top for the actual game development. Unity got C++ under the hood and chose C# as its script language. UE4 got C++ under the hood and got Blueprints as its "script" language...

    So they aren't that different in this respect...

    If you want to start learning programming, then C# is easier to begin with. You will be able to transfer a lot of your knowledge to C++ or Java in the future if you learn C# properly. Unity is a more user friendly game engine as well when you get the hang of how it is working. So it is a good place to get your feet wet.

    Both Unity and Unreal can be used to develop breathtaking games but it all depends on the skill of the developer or developers. Most people that make AAA games have spent lots of years studying and experimenting within their area of specialization... some have even gone as far as specializing within their specialization so don't expect to get there soon.

    My personal recommendation is to get the free version of Unity, visit the learning section on the Unity website. First get familiar with the game engine and then get familiar with C#. You can also visit Youtube later, there is lots of good tutorials there where they walk you step by step through the code in each video. Keep your projects as small as possible in the beginning.... get a cube to move... get cubes to interact with each other... add some graphics and make sure that you understand what you do while taking baby steps. You will avoid that you will suffer from a "burn-out" with tiny goals. You can also try areasa like 3D modelling, 2D graphics and so on... maybe programming isn't in the end your cup of tea. Games are developed by people with different skills that collaborate together and everyone is needed.
     
    landon912 and Ryiah like this.
  13. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    Unity does support C++. You just need either:

    a) To build your C++ code into a DLL/SO/Dylib which you then access via a managed wrapper,

    or

    b) a source code license.
     
    Ness, shkar-noori and MapuHoB like this.
  14. MapuHoB

    MapuHoB

    Joined:
    Aug 17, 2014
    Posts:
    50
    @Deon Cadme thanks for the thorough reply! Anyway I just got curious about the question no further intentions, like you said :d got hung up to the engine details. I have a bit of programming background, such as console apps with C#, algorithms and data structures C# and Java, a bit of C and C++, console games C# , already released 2 games with unity and currently developing another one. The thing is I'm probably not much into how these things in the background work and wanted to learn a bit more about it so I make my best choice for further developement.
     
  15. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,645
    I see this being thrown around a lot. Although it sounds plausible and even makes sense in theory, it totally falls apart when you start measuring. JIT-generated code is usually poor quality (Mono is not an exception), compared to one emitted by optimizing C++ compilers. They pretty naively convert bytecode to machine code and they have (almost) no optimization steps. They aren't to blame though - when you have 0.5 seconds to compile whole code, you can't afford spending time optimizing. C++ compiler, on the other hand, can take all the time it needs.

    I don't think that holds true. Mono JIT compiler uses a pretty safe, common subset of x86, AFAIK. I have never heard that it did auto-vectorization (and I doubt that too). I know for a fact that C++ compilers, however, do that.

    IL2CPP illustrates my points very well. If they weren't correct, we wouldn't see such significant performance increase with it :).
     
    Deon-Cadme, angrypenguin and Ryiah like this.
  16. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,954
    My knowledge of Mono's compiler is very limited, but it doesn't really surprise me. Does .NET's compiler fare better?

    Your point sounds suspiciously like "Mono's compiler is crap". :p
     
    Last edited: Jan 27, 2015
    Dameon_ likes this.
  17. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,614
    Well, not really. For its typical use case, which is UI applications, it actually sounds pretty good. Most of that stuff is "slow code" that doesn't end up running enough of the kind of thing where the kind of optimisation in question makes a practical difference for it to matter.

    Like @Tautvydas Zilys says:
    I don't want my applications taking 30 seconds longer to load to save me 1/100th of a second when I click a button.
     
Thread Status:
Not open for further replies.