Unity3D and c++

Will Unity3D ever support C++?

Currently, the industry standard is still c++ and it’s going to stay that way. If Unity3D would allow programming for not just the .NET standard but also the c++ Lib then their client base would surely double.

Studios that use Unreal engine are currently using it because C++ has better performance. If Unity3D adapted c++, more developers would come on board with Unity3D.

What is everyone elses opinions on this?

Is Unity3D going to support c++ in the future?

1 Like

The guts of Unity are written in C++. Mono is just the scripting layer, and it’s pretty standard for game engines to use something other than C++ for that. It’s often something much slower than Mono, too.

What’s more, if you are writing a script that needs to do some heavy lifting and moving it to C++ land would help, Unity Pro lets you write it as a native plugin and do exactly that.

And also, assuming that they’re reasonably well designed and written scripts are usually a pretty small portion of a game’s CPU time. If they’re not well designed and written, moving them to a lower level language like C++ is likely to make the issues worse.

Unity Free lets you use native libraries too - http://forum.unity3d.com/threads/181401-Unity-free-plugins-and-native-DLLs
Also you may use C++/CLI and mix the managed and unmanaged code in proportions you’d like. It’s not as comfortable as writing in C#, but surely possible.

1 Like

Studios that use unreal don’t use it “because it supports C++” but “because it’s unreal, with the whole feature set”. And unreal’s done in C++ because C++ was the obvious choice back then. People too often mistake “big thing Y is done X good because X is good” with “big thing Y is done in X because X was the only viable alternative when it was started and you don’t port over millions of lines of code for no reasons”.

C# is (simd co support aside) in the same performance league as C++, it’s within a few % behind / over depending on the scenario on anything but the simplest useless benchmarks

They already offer a source code license. Real-time tools for 3D, AR, and VR development | Products

WTF… I hope this is a joke.

It’s certainly not a joke, it’s well known outside of the fanboi / not reading crowd outside of syntetic benchmarks. Aside from the (very important of course) hardware instruction set direct support it’s just in the same league, being marginally slower or faster in some real word scenarios.

I can well provide a small sample that tests C++ being 1000 times faster, i can also do the exact oposite, but outside of 10 liners small loops syntetic programs that test nothing, yea they’re in the same performance league really, with a bit diferent performance characteristics tradeoffs (allocation being nearly free in C# but that cost being paid at GC time for example)

Small loops are critical to performance in some cases, though.

Both languages have their strengths and their weaknesses.

I believe, “synthetic” is the key word.

Yup +1 there, i’m not saying C++ beats C# on small loops, i’m saying making a small 10 lines program with a for int i = 1 to 1bajillon do something irrelevant is not a way to measure language performance, it doesn’t represent the performance profile of a real program

Studios that use Unreal engine probably wouldn’t have any problem getting the source code license of Unity.

Have you looked at C++ lately? It’s an ugly, and unintuitive language. Feels like trying to read aramaic. I start falling asleep almost immediately.

1 Like

C++ vs C#, here we go, ding ding… round 1 :slight_smile:

1 Like

Even the GC cost is unacceptable to many people. Do you think I enjoy that most unity mobile games have notorious a GC cleanup lag? There is a thread in this forum from people who think its the most important thing for unity to work on right now. The reality behind game performance is that tight loops run many times per second always take up the majority of the processor time. If I can reduce the loop time by even a small fraction I can get massive performance gains. Low level C++ specific optimizations and C++ profilers are disturbingly powerful. I once had a loop that I thought was as fast as it could possibly become. I ran my visual studio profiler, analyzed the profiler data and fixed my algorithm accordingly. It ran over 100 times faster.

DAMN IT!

Try C++11 its beautiful.

1 Like

Indeed, but my point is that the performance gain from effective use of small loops is not limited to synthetic benchmarks.

I know a guy who works as a consultant for large game and engine development companies. His job is to help them optimize their engines at the low level to get the most out of particular hardware or to meet target performance specs. A lot of what he does comes down to breaking big loops into little ones and re-architecting how memory is used to best suit those loops on the target platform. It’s not unusual for him to get performance gains in the same ballpark as the one Justin described.

I expect C# to be as fast or faster than C++ for the majority of everyday usage, and for the majority of coders (myself included, there). But when it comes to tasks where there’s real world benefit to be had from optimized low-level code hand-crafted for a specific platforms (the kind of thing I’d expect to find in the guts of a game engine) I’m under the very strong impression that C++ has real-world benefits.

Mind you, this exact conversation used to be had over C++ and assembly in the past. As compilers got better I (think?) it became moot, and I expect that in another decade (maybe even less) the same will happen here, too.

The gc issues people whine about are legit complaints about unity’s old mono. This has to do with unity not with c# also with the amount of per frame allocations they do
And vs’s profile for .net works just fine too. Read what i said again, there’s bothing wrong with tight loops in c# the key word was synthetic

It didn’t just become moot. It became reversed with compilers usually doing a much better job than someone handcrafting assembly.

Right. And when high-level language runtimes become consistently more effective than people who hand craft code as described above C++ will probably start to get superseded by more modern languages for those roles, too.

And we’re not there yet i’ll grant that (by no means you can write regular c# and expect it to beat intel’s c++ compiler+ custom code with compiler intrinsics for example) but it’s definately (once again simd similar exluded) already in the same league when writing normal code in both languages

By a non-managed language with only slightly more novice friendly syntax than C++ and only after I have long been dead from old age.