Unity and more widely open source availability

There was a short discussion about Unity source access [in this thread (link to the first post in the conversation)]( Unity Future .NET Development Status page-28#post-8643051), and I hadn’t seen any dedicated discussions about the topic lately, so I thought this could serve as a central place to talk about it.

Current state

Unity is written in both C++ and C#. The C# side of the engine has source code available for reference (viewable here), but not editing; you cannot make changes and recompile it into a new executable without using tools like Mono.Cecil. The C++ side of the engine has never been released publicly. As of October 13, 2022, read-only source is available to Unity Enterprise customers by default and to Pro customers as an add-on. It’s not clear if either of these options also include the ability to modify the source and recompile, or what the cost is for Unity Pro customers to purchase access (I assume it is on a case-by-case basis).

Source availability vs. Free and open-source software (FOSS)

Software that makes its source code available is not necessarily without constraints. The widely known MIT license (e.g. curl)) is very liberal in this regard, allowing anything from modification to redistribution of the code and software. The GNU General Public License (e.g. Blender) is a bit more restrictive, requiring developers to make any modifications freely available. At the other end of the spectrum is Epic Game’s license for Unreal Engine’s source code, permitting modification but heavily restricting redistribution and requiring royalties to be paid for any product using any part of the code (more on Unreal later).

Why does having source access matter?

While the most obvious benefit to having source access is the ability to directly modify the behaviour and expand the limitations of a piece of software, this is not the only way users can benefit from source code availability. Unreal’s FAQ states it nicely:

Being able to read through the source code of a tool immensely aids in your understanding of how it works and what its limitations are. This can hugely speed up the process of debugging, profiling and make it much easier to evaluate whether something will or will not be capable of being able to solve a specific problem.

When this knowledge is shared, it elevates the community’s understanding of how the tool works; queries about the functionality of internal modules can now be answered by any member of the community who has read the code, rather than only internal developers themselves. As well, once the community has source access, it opens the door for contributions back into the codebase (more below on how Unreal handles that).

Case study: Unreal Engine

Unreal is probably the tool most often compared to Unity. As stated above, it freely offers the engine’s source code to all members of the community (i.e., people with Epic Games accounts) for viewing and modification. You can read more in-depth about their license in the Source code section of their FAQ, but to summarize:

and

Developers are also limited to only sharing code snippets under 30 lines in public forums.

The code is available for viewing when you create any project in Unreal. Ever wonder what happens when you try to destroy an Actor (the GameObjects of UE) in Unreal? Simply right-click the function call and Go to definition… (or, if you are using Unreal’s visual scripting tool, double click a Destroy node to automatically open Visual Studio to the source).

bool AActor::smile:estroy(bool bNetForce, bool bShouldModifyLevel)
{
    // It's already pending kill or in DestroyActor(), no need to beat the corpse
    if (!IsPendingKillPending())
    {
        UWorld* World = GetWorld();

        if (World)
        {
            World->DestroyActor( this, bNetForce, bShouldModifyLevel );
        }
        else
        {
            UE_LOG(LogSpawn, Warning, TEXT("Destroying %s, which doesn't have a valid world pointer"), *GetPathName());
        }
    }
   
    return IsPendingKillPending();
}

Complete with the original comments.

If a user makes a modification that would be widely useful, Epic Games takes pull requests to the codebase (see the Contributions section of the GitHub repo) and has a page dedicated to helping developers make quality contributions.

Why should Unity make their source more available?
Unity is filled with many small and large annoyances that could potentially be resolved by giving primary stakeholders of the engine (the developers) the ability to fix these problems.

As well, Unity is already moving in this direction; despite the C# side of the internal engine code not being available, a huge amount of Unity’s newer modules do make their source available through the package manager ( as @MelvMay notes in this post ). This includes some of Unity’s largest and most complex packages like the ECS framework and Unity Physics.

Examples where I have used source access

  • I modified the InputSystem to be capable of interacting with multiple EventSystems simultaneously for my VR vs. PC project (as with local play, the PC and VR players can interact with the same menu independently).

  • I integrated ProBuilder’s internal Box Projection mapping function into my project’s build pipeline to generate projected UVs for non-ProBuilder meshes.

  • For my website, I needed a code highlighter that would allow me to highlight segments of individual lines, something that the tool Eleventy (the site generator I use) was not capable of. I was able to implement this functionality by reading through Eleventy’s source code and creating a modified highlighter.

  • Our project uses Photon Fusion for networking. At build time, Fusion registers all network objects in the scene and spawns them at runtime–including disabled objects. This was undesirable for my team, so I was able to modify their editor script to include only enabled objects.

Arguments against Unity moving to a move available source model

As seen with Unreal, there’s a lot of work that goes on around making your source code available. The licensing and legal side needs to be managed. Documentation on how to access and build the code needs to be written. Handling pull requests properly requires best practices to be laid out and developer time to be allocated to review and merge contributions.

I do not have access to Unity’s source code, and so I do not know how much work would need to be done to make it easily buildable by external users (I assume at least some of the work is already done, since as noted above it is currently available to some customers). I also am not in the business of building game engines, and so cannot comment on the legal or financial side beyond presenting Epic Games as a precedent. Obviously Unity’s revenues from selling the source access would be affected, but I have no idea if that income is substantial or not.

To conclude,

I probably don’t need to note that I’m a big fan of source availability when working with tools, since having source code to me means the removal of limitations; we can look at the fantastic work that has been done with the Mario 64 decompilation project as an example. I’m interested to hear other perspectives on the topic, and if anyone has any corrections to make to the above please do so, as I’m certainly not an expert in software source licensing and whatnot.

20 Likes

As I see it, here’s the big problem with Unity’s current lack of source code access:

  • You encounter a bug with the engine. It’s a simple bug and the fix only requires one or two lines of code to be changed.
  • You really want to fix it yourself so you can move on with your life and the project, but Unity does not allow this.
  • You make a bug report.
  • Two months later, you get an email from Unity that they have investigated your report, confirmed that it’s legit, and are maybe thinking about possibly fixing it.
  • Two years later, there’s finally an LTS version of Unity that has the one-liner bugfix integrated.

This happens to me very frequently, especially when I’m working with more obscure engine features. I spend TONS of my precious development time figuring out messy, hacky workarounds for Unity bugs because I have no ability to fix them myself and waiting for Unity to fix them is impracticable. I wish I could instead spend that development time fixing the underlying bug, for me and also for everyone else who uses Unity.

Furthermore, the lack of source code access makes it very difficult to understand how engine features really work, especially for parts of the engine that have minimal or missing documentation. Sure, the C# code is available for reference, but >50% of that is just external calls to the private C++ code!

I am seriously considering switching to Unreal or Godot for my next project, and that’s almost entirely due to the full availability of the source for those engines. I’m so, so tired of working around and against Unity’s closed-off codebase. It feels so fucking pointless.

23 Likes

Counter args - “Developer” fiddles with source code many times. THEN he introduces a bug that under certain conditions introduces catastrophic failure. That failure was dependent on some other code they fiddled with prior…maybe… “Developer” then inundates Unity with bug reports. Developer doesn’t have a clue and Unity is supposed be his personal tech support? Not a good business model all altruism aside.

5 Likes

Well “Developer” should always test their bugs in a clean environment, if in doubt!
And if the issue keeps occurring, even in a clean Unity Version, only then inundate Unity with bug reports!
Capish?

3 Likes

Easy fix: require bug reports to contain sample project without any source changed.

I did it many times where my big project with a lot of packages changed had Unity bug and that was the only way to be 100% sure.

9 Likes

The only counter argument to not distribute the source is the paywall that exists today to access it, which IS an acceptable argument (this may be one of their main source of income, who knows). But nothing else makes sense to use as counter argument.

So the question is: is it doable financial-wise?

1 Like

Obviously, source access will do only good for the engine in the long run. But do we actually expect to get any sort of answer here from unity except polite “won’t do, sorry”?
It is usually unity devs who browse these forums and if they could go open source, they would do it long time ago I’m sure.

I’m gonna contribute though to the list of stuff source access would be nice for

  • I hate built in object picker so much, I used Harmony2 to modify source of object field
  • With newer graphical APIs, NativeRendering plugins become practically useless ( case 1 , case 2 ) unless you know more about internal structure of the engine
  • I would very much like to have heightmap collider exposed properly instead of TerrainCollider, which is annoying to work with because it will create heightmap texture no matter what (Actually all of terrain in unity is just a joke that has to be replaced)
  • No way to get directional light projection matricies! SRP code has method to do it, but its stupid placeholder, and they actually mention in C# source that they should replace method in future (it accepts light index and culling results (??) instead of reference to light itself)
  • Runtime access to animation clips! Custom nodes in animator!
  • In general, unity’s design leads more to being bunch of APIs and unlike unreal, we don’t have “the unity-way” to do things. You kinda just make “your own version” of the engine during development. Which is not necessarily bad, but in this case source code is even more desirable

They could still sell it but with more reasonable price (price increasing for every dev or 1% rev share etc). I think the main counter argument is that they are worried of someone stealing source code but let’s be honest:

  • Unreal does a lot more next-gen features and aren’t scared
  • someone that would benefit from stealing source code probably have enough money to buy it already
2 Likes

Think I remember some dev saying why this is neigh impossible: The C++ side contains stuff that is under foreign licences. They have a monetary agreement with those licence holders to allow sharing the source with paying customers but they could not afford a licence that’s open for everybody (any licence holder in that position will charge a ton from Unity and Unity cannot really hope for a jump in revenue from that step since the customers who have money already do pay).
So fear this wish and argumentation in the thread is a bit fruitless…

4 Likes

I am strongly in the camp that prefers source access but I’m painfully aware there are a two reasons that make it quite unlikely for Unity to change their current status quo regarding their C++ source:

  1. Unity uses a host of licensed 3rd party tech (eg: Umbra, FMOD, Enlighten) they can’t just broadly give access to by flipping a switch because it require signings papers and going through pricey bureaucracy. BTW, Unreal and CryEngine had the exact same limitation before UE4 and CE5.

  2. Allowing anyone to recompile the engine would make it harder for Unity to enforce their subscription policies: people could just compile out all licensing and tracking stuff and go their merry way.

FOSS in unity is not happening. THe point of FOSS is to allow other people to take your work and use in their projects for free.

Unreal is not opensource, their license is quite restrictive. For example, you’re not allowed to post a whole lot of code online.

Also, unreal source code is not rainbows and sunshine. Just because you have source code access, it does not mean you’ll be able to learn from it, fix it or make sense of it. A simple method can go elven levels deep and jump through multiple components, and if you realy on its inner workings you learned through the code dive, then in the next update things you used might end up destroyed, refactored away, or completely changed. Everything you see in the source code is undocumented functionality and is subject to change. What you can be sure of is public-facing API.

3 Likes

Note that this discussion is not intended for Unity to move to a FOSS model, but rather using Unreal as case study (I make note of the restrictions on Unreal’s source licensing in that section of the initial post).

I agree that is a challenge with working with large, old codebases, but this is a hazard around making use of any source available project, including modifying any of the C# Unity Packages (I use the Needle mirrors on GitHub to pull in changes, but you are pre much required to test and vet it when you upgrade). Even with those steps, I still really appreciate having the ability to modify the code, and understand it more deeply.

I’ve seen this mentioned a few times, would be nice I suppose to have an official reply on it. How did UE and CE solve the issue? Via reaching a deal or just replacing those components with proprietary code?

I wonder how Epic handles this. In Unity’s case, you can of course just not pay the license fees and wait for them to audit you, so I’m not sure if removing that kind of code would serve much purpose (unless you really, REALLY don’t want the splash screen).

2 Likes

UE4 source pretty much doesn’t have any code related to consoles

I heard that they specifically made UE4 without third parties for the sake of source code, and also that UE4 development started in like 2000s, took about 10 years

For all we know, Sony could sue Unity for having even hint at how PS4/5 work. Like having specific branch with comment mentioning PS4 architecture might be enough to break their licensing.
All the more reasons we should get Unity6 instead of yearly updates if you ask me :stuck_out_tongue:

1 Like

I don’t know how you came to that conclusion from that. All that line is saying is that you need to be a licensed for the consoles. Once you have the licenses you simply contact them and they provide download links to the source code for the consoles that you have access to.

Ah, the weekly why garbage Unity isn’t the wonderboi Unreal thread on the General Discussion.

4 Likes

Like I said… “it is not rainbows and sunshine”, and in your case the case study is a bit one-sided.

People bring up source code access as if it was a silver bullet that magically would solve every problem.

I’d like to stress that the situation goes beyond “challenge of working with old codebases” and put it into perspective.

Codebase of UnrealEngine is over 300 megabytes of code. You won’t “understand” it at any given time. The main issue is that the moment you dive below the official API, you’re in No Man’s Land, which is unsupported and in constant state of flux. So you dive in, see something, assume “Aha, that’s how it works”, and t he next release they might scrap the whole thing you were relying on.

For example around version 4.12 of Unreal Engine I needed something basic like making pathfinding control root motion. At the time I was quite surprised to discover that pathfinding code is spread through seven different components, hijacking it was an interesting adventure, and then once I made root motion work, in the next minor release they altered the part I relied on, breaking the code I introduced.

The interesting thing is that Unreal has been slowly copying Unity’s practice. For example, originally C++ documentation was trash and did not exist at all. That slowly started to change. Originally the site did not host archived API references for previous engine versions (that was fun), only latest was available. That also started to hcange.

The point is, while code access would be nice, it is not strictly necessary, and documentation might be more mportant. C++ bindigs would be nice, though, and those could be provided without source code access. See how 3dsmax/maya originally handled 3rd party plugins, for example…

In the end Unity does strive towards more openness. A bunch of components have been moved into packages after all and those are automatically open source and can be edited. No direct way of contributing sadly, but it is something.

Yes. It’s not just because it’s a revenue stream (licenses in general are less revenue than services and advertising), but because there are multiple licensing issues that would have to be overcome before source could be made accessible in the first place.

This whole idea that the source should be widely accessible rarely touches on the reality of the situation.

Just open source the C# side is fine for me. At least I can debug and fix bug that was really in C# side. It also possible to upgrade some parts that was not really need to be C++ and skip over to write in C# if there is a bug in C++

Especially the editor code and build process that really just extend in C# and could just call C++ code only where it needed

Eventually I wish unity would purely be written in C#. Today C# are performance enough and there is also NativeAOT and many functionality that can make C# as fast as C++

On the other hand I am curious if there is foreign licences thingy, how they can sell the pro license? Or is the license just charged unity for the number of accessor?

4 Likes

Different business model. Unless you sign for a custom license, you owe Epic 5% of the yearly gross revenue past 1 million USD generated from software distributed to end users using Unreal Engine code. It’s hard to stay under the radar if your product hits that much revenue.