Why does unity support neither C++ nor Java?

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?

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.

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#.

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.

Should I understand that it’s hard or not good idea to add a programming language to a game engine rather than scipting language?

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.

1 Like

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?”

5 Likes

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.

2 Likes

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?

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.

2 Likes

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.

2 Likes

@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.

2 Likes

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.

3 Likes

@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.

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 :).

3 Likes

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”. :stuck_out_tongue:

1 Like

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.