Unity: Workaround for 4GB limit 2019

In the past projects I have been involved with we had a need for many large textures, which would often mean we would get build errors because Unity is unable to address more than 4GB in ressource files. This limit is per scene, which means your total build may very well be larger than 4GB, but a single scene cannot.

I looked into asset bundles but I could not find a way to use them for my scenario and they only seemed to add additional headache without actually getting closer to a solution.

A bit of explanation: Each scene included in your build will result in a sharedassets0.assets.resS file. Additional scenes will be named sharedassets1.assets.resS, sharedassets2.assets.resS and so on. If the same file is referenced in multiple scenes it will be packed together with the first scene it is encountered. Knowing this, we can make a very workaround for this limitation.

The idea is to create additional scenes which sole purpose is to create references to assets, and thereby causing Unity to package those assets with our data scenes.

Step 1 is to create a script that can hold a reference to anything.

using UnityEngine;

public class BuildDependencies : MonoBehaviour
    public Object[] assets;

Step 2 is to create a new scene, let’s name it assets1, add our script and add any asset we would like to package together to the assets array. Just make sure their total do not exceed 4GB.

The final step is to then add assets1 to the list of scenes included in the build and ensure that they are placed higher than our actual scenes. The final list of the scenes included in the build may look like this:

0. menu
1. assets1
2. assets2
3. assets3
4. level1
5. level2
6. level3

Et voilĂ .

It is worth noting a few things about sprites, textures and sprite atlases. First of all, adding a sprite atlas to the list of objects will be enough to include all the sprites packed into that atlas. Secondly, you should not add both the Texture2D assets and sprite atlases to the assets array, as this would result in both the texture assets and the sprite atlases being added, effectively doubling the size. Similar caveats may exist for other asset types as well.