- Home /
Creating a Unity Moddable game
Hi, what is the best approach to create a game where users can create mods ? I want the users to be able to create custom mods changing scenes and assets.
I thought about using a file based system but then I might loose all Unity benefits. Alternatively user could create scenes in unity export them as packages and then I could load those scenes at runtime, but I don't know if out of project scene loading is feasible.
On the game GUI the user can load a mod from a list of mods A script will load all the assets as follows (it is a rough idea) - import meshes - load the scene data - play
Thanks Fred
Answer by Max Kaufmann · May 05, 2010 at 08:27 PM
Unity uses .Net so users could compile their own Managed DLLs which you can load using WWW and JIT with System.Reflection.Assembly (http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx)
However, only classes in the bootstrap unity3d file can implement MonoBehaviours, so you'll have to create a plugin host interface for your modders, e.g.
interface IMod { void OnModWasLoaded(ModHost host); void OnUpdate(); void OnModWillUnload(); ... (game specific hooks) ... }
class ModHost : MonoBehaviour { IMod userMod;
void Start() { userMod.OnModWasLoaded(this); } ... (etc, etc) ... }
There's some caveats w/r/t how you get the DLL from your host unity game for moders to link against to get the interface (the internal DLLs are in $Project/Library/ScriptAssemblies/). Simply giving them IMod.cs won't fly because .Net won't consider them the "same" class (each assembly declares an implicit namespace).
If your modders have unity they can publish and load their own asset bundles. Alternatively, you'll have to implement your own content interface.
Hope that's enough to get you started ;)
$$anonymous$$ax, thank you for your answer. I was not thinking about users being able to create their own dll's but basically to be able to create a mod changing assets /terrains only. The project is a small flight sim (I already have the aerodynamics part) ideally the modder could add a directory in the assets folder with his terrain, meshes, and xml configuration file. Based on a GUI list selects a terrain a plane and I load everything from the X$$anonymous$$L data. $$anonymous$$y question is does this break the Unity asset management ? can I create a complete terrain, including trees, from script?
thank you Fred
Answer by mvportiera · Aug 08, 2016 at 07:13 PM
If you want to give modders full control then you can make the Assembly-CSharp.dll and UnityEngine.dll from you most recent build available. Then anyone would be able to take control of the game. All you would have to do is provide an entry point and for the mods and a way to load .dll files at run time. For example you could make a mod interface as an entry point. Then when you load the .dll file you could check if a class implementing the interface exists and if so call its method. To do this however you will need to use System.Reflection and probably System.IO.
Your answer
Follow this Question
Related Questions
How do I expose a folder in my build 1 Answer
How to read an OBJ file outside of unity,How do i read an OBJ file outside of unity? 1 Answer
Are we allowed to modify UnityEngine.dll and sharing it? 3 Answers
Any way to let users create scenes or prefab in one project and load them at runtime in another? 1 Answer
Game Modding Simulator Racing Game 0 Answers