I have a project that will necessitate the need for a level builder (or rather I would like to provide functionality to do so). I have been musing about the idea of straight up using unity for the level builder. Perhaps distributing an asset that has all of the required game hook type objects (in general terms think spawn point prefabs, item prefabs, etc) and then letting a user use unity free to build a level and somehow save their level as an asset bundle, then use my game to load it at run-time.
The big benefit of course is the user is building level the exact same way I would and using a full set of unity tools and the entire asset store ecosystem to do it.
I doubt I am the first to ever consider this, has anyone done this or something similar? Any thoughts on potential gothchas? Any ideas on how to approach this?
My first thoughts are distributing a set of monobehaviors that they must attach to any gameobjects or prefabs they include in a bundle. These would allow the main game code to hook up correctly to any objects they create. But leaving most of everything else up to the user.
I could distrubute a dll of a scaled down runtime of the main game that would allow them to run a level in the editor (otherwise they must export they level as a asset bundle then run the level in the game to debug any issues). The issue I see here is that if I use ANY asset store assets I would be exposing them to a regular unity user if they were included in the dll.
Been talked about before a number of times by people wanting to provide some type of moding, short answer is that AssetBundle is a pro only feature and most would not want to make that investment just to “mod” a game. You can build your own level construction tools into your game though that is no small task.
Forgot about asset bundles being pro only, that is a bit a game ender for this route.
This is one of those things that if Unity could support natively it would attract a great deal more traffic to free and probably bolster asset store sales as a side effect. It funnels mod level creators through Unity which can only help them long term. Perhaps Unity 5 could make assets bundles available to free for this purpose. Perhaps some digital signature that would allow asset bundles to be created in free for game clients that were created with Pro. They aren’t likely to do something like this but would be cool none the less.
You can still use Unity as a level editor without asset bundles, but you’ll need to implement the saving and loading of the levels yourself. Essentially you’d write a script for the editor that scans the level’s GameObjects and spits out a custom file containing the level data.
Then you’d load in the level data, meshes, materials, scripts, etc at runtime and set everything up. Mesh loading will require you to write your own model importer. Scripts will need to be compiled with Mono and loaded in with System.Reflection.
I did this once. My levels were constructed entirely from prefabs which had unique IDs. A level could be made in-game or in the Editor, as it was a list of the IDs and positions of the prefabs.
There was of course a whole bunch of other stuff on top of that so that you could do interesting things with it, but that was the base.