# Reducing total file size of multiple Unity games

Our product consists of many small stand-alone games, some made in Unity and some made in other languages. These games can be launched from a hub. The file size of the Unity games is quite large, since each game is being build to work as a stand-alone game. When looking inside the folders, I can see that many of the files, folders and dlls are the same, so I thought that it would be possible to re-use these across all the games to reduce the file size of our installer.

So far I have successfully moved the games' exe and _Data folders into one folder so they can re-use the MonoBleedingEdge and UnityPlayer.dll, but I was hoping to be able to share even more resources than this. All the games are built using Unity 2019.1 and all of them are using many of the same libraries and dlls.

Does anyone have experience bundling many Unity games like this? Is there some configuration for Unity that will help with allowing shared resources?

• Can your installer notice that a file is the same and store it only once (and copy it multiple times upon installation)? Feb 7 '20 at 11:42
• Yes, it can do that. I just need to know then which files can be shared and which can't - when I e.g. tried to copy files from _Data/Managed into other games, the game would launch but not work properly Feb 7 '20 at 12:11
• Likely, those who have the same CRC/hash would be shareable? I don't know. Feb 7 '20 at 12:28

One option could be to merge all these Unity games into one game with multiple scenes. That way you will only have one copy of the Unity runtime environment and of any shared assets.

When that game is launched, then it does of course need some way to tell which scene the player actually wants to play. One way to do that is to have the hub application start the Unity game executable with different command line arguments. Like unity_games.exe tetris to play Tetris or unity_games.exe pong to play Pong.

The game itself would then have a start scene which just uses the method System.Environment.CommandLineArgs() from the .NET standard library to detect the argument and then switches to the appropriate scene. Unfortunately that method won't be available on every target platform. So please verify that this method actually works on all the platforms you want to target.

Oh, and do not just do

SceneManager.LoadScene(System.Environment.CommandLineArgs()[0])


Your players might figure out that this allows them to go directly into scenes they aren't supposed to reach directly. Use a switch-statement instead which maps known game names to scenes:

switch (System.Environment.CommandLineArgs()[0]) {
"pong":
break;
"tetris":

• @Daniel The 2d and 3d physics engines of Unity are completely separated. The difference between a 2d and a 3d project are just a couple editor presets. You can even mix them in the same scene without problems (the 2d and 3d colliders just won't interact with each other). What does get tricky is if two games both use the same physics system but require different settings for that system. In that case you might have to set the correct physics settings at the start of the game through the Physics / Physics2D class. Feb 7 '20 at 12:13