so are the scripts in unity being "compiled" or "interpreted"?

Noobiest question of the day, I know. You see, I was checking out this great tutorial on lynda.com Foundations of Programming Fundamentals1_4 - YouTube where they explain the differences between compiled and interpreted languages, to sum up what I can gather:

  • compiled languages are those that need to be converted into an executable for the application to run
  • Interpreted languages are interpreted at run-time, never turned into an executable.

So what I can deduce from these ridiculously simplified definitions is that all my scripts in unity are being compiled since I can build my project into a, say, an .exe file in order to publish it on Steam, for example. However, I remember in a live training video in the unity webpage (I honestly can’t remember which one) someone corrected Mike Geig telling him that “scripts in unity are not being compiled but interpreted”… so what gives then? are scripts in unity being compiled, interpreted or some hybrid like the video tutorial of lynda mentions? Thanks in advance for the answers and sorry if this is way to nooby, I’m new in the world of programming :confused:

2 Answers

2

It is being compiled. You can find the dll of the scripts. I would think the term interpreted is used since Unity is running C++ with wrappers to call the C# side but the scripts are compiled.

Interpreted is used for server(Php,Python)/client(Javascript) side code as you can see the actual code (Right click show source code) then the browser or the server is running the code.
Unity does not seem to do that.

But whether is compiled or interpreted would not make any difference on your side.

thank you so much!... something I've been thinking since I wrote this question: maybe in the live training tutorial what they meant was that the scripts were being "interpreted" when you are testing your game in the editor? Since there is no need to build your game to try it out here. Had no idea unity was made in C++, thanks again!

Probably interpreted as turn into native code during runtime. C# is converted into Dll ( see C# Intermediate language) while the game runs in C++ calling wrapper methods for the C# part. So in some ways, it could be thought of interpreted since the game runs and converts the Dll into native code at runtime. But honest, don't bother about this issue, Unity developers have spent long hours in the making so that you can focus on development. Leave the internal functioning to them.

I figured it wasn't really an important question but I like having these kind of details clear since I'd love to take programming and game-making as a real job some time in the future, thanks a lot!

Yes, they are compiled; for reference, see here.

This does make a difference for virtually all Unity developers as we have to wait for a fairly lengthy compilation phase (proportional to how much code you have, and how fast your CPU!) to complete before we get to test any changes to the code.

Reading the suggested reference it will be made clear that compiled/interpreted is a matter of degree for many languages such as Java or C#.

NOTE: weirdly, it seems that the compilation phase carried by Unity is not incremental - if it were, only the latest changes and some dependencies would be recompiled, and the wait would be reduced to almost insignificant.

The advantage of ‘more compiled’ vs ‘more interpreted’ is more compiled yields better performance.

‘More interpreted’ makes the test-tweak-retest loop way faster, making interpreted languages such as Python a great choice for many game designers.

Of course that isn’t the only criterion, otherwise we’d all be developing games in Python : )