Do games made with Unity using C# are (dot)NET dependant?

Hello there,
I’m new to Unity so maybe you will find my question a bit weird :slight_smile:
I understood that Unity uses C# as a scripting language. Does it mean that the final project (a game in my case) will be a C# program (.NET dependant), or Unity translates the C# scripts into another language (making the final game .NET independant)?
Thank you in advance for your precious help!

The Unity engine is written in C++ and is its own standalone program. On top of the base C++ engine there’s a scripting engine.

Depending on whether you’re using IL2CPP your scripts come along with the game either as .NET CIL, or native compiled code.

When you aren’t using IL2CPP, Unity includes the Mono runtime, which is an open source .NET implementation.

In either case, Unity includes all the libraries it needs to run your game in your built game. There’s no dependency on the system having .NET installed.

3 Likes

You do not need to load an external library when your game is installed on a customer’s machine if that is what you are worried about. Unity uses Mono, an open-source, clean-room replacement for .Net and when you build, a Mono Runtime is included in a build.

Plus, Unity comes with a bit of technology called ‘IL2CPP’, which can during build translate your C# (.Net) code to c++ (‘cpp’) and then compile towards that library. It’s a technological tidbit, really, not something that should concern you.

What is it exactly that you are worried about?

Thank you for your answers. It helps me.

Why did Unity choose an interpreted language (such as C#) instead of a compiled language as C++? Maybe I’m wrong, but I guess a compiled language is more performant than an interpreted one. Is it to be platform independant?

Much has been written about this. A great deal of it provides more heat than light. Here’s my own short take:

  • You will very rarely see a meaningful performance difference between C# and C++ (and when you do, it won’t always be the same language that runs faster).
  • Having spent many, many hours of my life plugging memory leaks, I will never use an unmanaged language again if I don’t have to.
  • C# is not interpreted. It is compiled to an intermediate language which is then compiled at run time by the (I’m not make this name up) Just In Time compiler. Put your faith in the JIT. It does things at run time that wouldn’t be possible at compile time, and you’re glad it does them.
3 Likes

It’s a strategic decision, with portability to different platforms and serviceability being important aspects. That being said, as @Stevens-R-Miller already pointed out, nowadays there are few if any performance differences, and few modern applications are truly compiled into processor-specific machine language any more. For example, if you program in C++ or ObjectiveC on the Mac with XCode, your code too is compiled to an intermediate language and then runs on a virtual machine (LLVM), which is much safer and much easier to memory-manage. The same principle applies to Unity. LLVM and their brethren are fast. Not as fast as possible, but increasingly, games are constricted by graphics performance, not CPU, so a slight drop in code performance is a nice price to pay for having access to modern technologies (of which automatic garbage collection is only one).

Additionally, many studies have found that managed code, and automated run-time optimization is much more effective (and performant) for the average programmer (BIG caveat, there will always be edge cases where hand-optimized code runs better, but this requires a ton of knowledge and a megaton of talent). Finally, todays applications rely on large frame works and libraries spend most of their time in pre-compiled libraries anyway, so the impact of a LLVM-managed short code segment is usually not that significant.

2 Likes

Agreed. Throw in hardware help like pipelining, prefetch, multiple cores, etc., and the speed “advantage” of native code pretty much evaporates.

C# is a compiled language, not interpreted.

2 Likes

I wouldn‘t entirely agree. I know this is splitting hairs, but I feel that the OP perhaps meant ‚compiled‘ the more in traditional way. Traditionally, compilers worked slightly different: they took source code, and converted that code to a specific machine language. The code wasn‘t portable at all, and only worked on that type of processor, but the processor could load and execute the instructions directly, at native speed.

Today, this is different. When doing its magic, compiler first builds an abstract intermediate version of the source code until it is ready to be translated to machine language, and all references, expressions and symbols have been logically (but not absolutely) resolved. It is then used to generate machine code during the code generation pass. However, it should be noted that the abstract intermediate has two important properties: it can be persisted, and it can be interpreted.

And since the abstract version is also portable to other machines/processors, bright minds separated the code-generation and abstraction steps. Once you save the abstraction (heck, even Wirth‘s UCSD Pascal did that, it‘s an OLD concept), you can either interpret it (even on different machines), or compile/link it in real-time during loading (this wasn‘t feasible in the 1970‘s, but became viable during the early 90‘s). This is what modern languages like can C# do (both interpreting and just-in-time code-generation from the intermediate).

So, yes, C# is a compiled language, as there is a compiler at work. But the compiler does not generate machine language, at least not as the end product of its pass. Modern compilers generate the intermediate abstract code that can be loaded and then interpreted and/or compiled on multiple different hosts - which is so incredibly cool. So C# can also be an interpreted language, depending on how the host VM that runs the code is set up.

As I warned above: I‘m splitting hairs here. :slight_smile:

Hi, sorry for bring up this very old thread. But I was surprised today by a player of my game that is asking about why our game is asking him to install .NET Framework 3.5
9442487--1324811--image.png

I don’t think I did anything special with my game, or if one of the assets i’m using is doing this. But is there something I can double check to make sure this doesn’t happen?

Thanks!

Please don’t necro-post. If you have a new question, make a new post. It’s FREE!!

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

  • Do not TALK about code without posting it.
  • Do NOT post unformatted code.
  • Do NOT retype code. Use copy/paste properly using code tags.
    - Do NOT post screenshots of code.
    - Do NOT post photographs of code.
  • ONLY post the relevant code, and then refer to it in your discussion.