1
\$\begingroup\$

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?

\$\endgroup\$
3
  • \$\begingroup\$ Can your installer notice that a file is the same and store it only once (and copy it multiple times upon installation)? \$\endgroup\$
    – Vaillancourt
    Feb 7 '20 at 11:42
  • \$\begingroup\$ 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 \$\endgroup\$
    – Daniel
    Feb 7 '20 at 12:11
  • \$\begingroup\$ Likely, those who have the same CRC/hash would be shareable? I don't know. \$\endgroup\$
    – Vaillancourt
    Feb 7 '20 at 12:28
2
\$\begingroup\$

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":
        SceneManager.LoadScene("pong_titlescreen"); 
        break;
    "tetris":
        SceneManager.LoadScene("tetris"); 
        break;
    "fifa20":
        SceneManager.LoadScene("fifa19"); 
        break;
    default:
         Debug.LogError("unknown game: " + System.Environment.CommandLineArgs()[0]); 
}
\$\endgroup\$
3
  • \$\begingroup\$ I thought about using command line args as well, but some of the games are 2D and some are 3D and are thus using different physics settings, which stumbled me when I looked at this approach \$\endgroup\$
    – Daniel
    Feb 7 '20 at 12:06
  • 2
    \$\begingroup\$ @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. \$\endgroup\$
    – Philipp
    Feb 7 '20 at 12:13
  • \$\begingroup\$ @Daniel You might encounter the same problem with the render settings. This problems could be greatly alleviated by porting the games to the scriptable render pipeline (if they aren't already), because this allows you to treat render setting configurations as regular assets. \$\endgroup\$
    – Philipp
    Feb 7 '20 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.