1
\$\begingroup\$

I know that the Unity editor can import/export packages which could contains Scenes (levels), but is it possible to import a Scene into a game at runtime without the Unity Editor?

What I am trying to achieve is:

  1. The client should only need to download/install the game once.
  2. The original game would NOT include any Scenes/levels except the start-up Scene.
  3. The original game would also not be aware of any levels so that developers can create more levels AFTER the game was released.
  4. The client should be able to place separate pre-created level-files (whether in some Unity scene format or any other format) into some directory where the game can at RUNTIME import these files without the Unity Editor.
  5. After the game imported these levels, the game should be able to play those new added levels without re-compiling/restarting.

Before I go and create my own special level-format and Unity Scene exporter/importer I was wondering if this problem has not already been solved.

\$\endgroup\$
  • \$\begingroup\$ You need to study serialization, saving and loading files, encrypting these serialized files and also decrypting them and de-serializing. There's no inherent support for importing a level pack during runtime the same way you do it in the editor, and you wouldn't want to be doing that anyway (for security and performance reasons). \$\endgroup\$ – John Hamilton Jun 8 '17 at 11:40
  • \$\begingroup\$ Security is not a concern. I don't mind if people reverse-engineer the levels. I know how to serialize stuff, but I also don't want to reinvent the wheel if someone else already found a way to load Unity Scenes at runtime. \$\endgroup\$ – Jasper Citi Jun 8 '17 at 11:55
  • 2
    \$\begingroup\$ I haven't used it yet in my projects, but AssetBundles seems like a good choice in your case. \$\endgroup\$ – Aditya Yadav Jun 8 '17 at 12:06
  • \$\begingroup\$ I would expect that you could use AssetBundles and have the game keep a list of all installed AB scenes to choose from a picker after the game loads. You'd probably be best to ensure the bundles are named something specific, perhaps using a prefix of MyGameName_, so it knows what bundles to use in the scene picker. Good luck! \$\endgroup\$ – Jesse Williams Jun 8 '17 at 12:11
  • \$\begingroup\$ Cool, I will look into it. Maybe I am wrong, but from what I can see it seems like the game needs to know about the AssetBundles at build time. I am looking for a dynamic solution where you can load any "AssetBundle" afterwards at runtime even ones that have not been define at build time. E.g. it should be able to scan a directory and detect all "AssetBundles" not yet loaded and load them even if they were created months after the game was released. \$\endgroup\$ – Jasper Citi Jun 8 '17 at 12:12
1
\$\begingroup\$

As mentioned in the comments, Unity has AssetBundles ( https://docs.unity3d.com/Manual/AssetBundlesIntro.html ).

These can be loaded at runtime with the 'www' class (if they are stored locally, you can use a file:/ URL, or if they are remote you can use http://).

However, there's one major word of warning. For security reasons, these bundles may NOT include scripts. So if the scenes in these downloadable packages need specific code, you'll need to embed that code in the main executable.

You'll also want to be comfortable that everything is right with your scripts - if you change the parameters a script needs, you'll need to re-build and re-deploy any asset bundles that use it.

Asset Bundles may also be platform-specific (ie. if you are deploying to PC, IOS and Android, you may need to create three different bundles - one for each).

However, they do allow you to load in large chunks of objects, models, animations etc. fairly seamlessly.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Excellent. I am going to try this. To bad about the scripts but I guess it make sense. As a workaround I will have to deploy the game with a library of scripts that is available to the level-designers. Not a crisis, but just something I need to keep in mind when I design the game. \$\endgroup\$ – Jasper Citi Jun 9 '17 at 9:23

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.