Search Unity

Modding a Unity Game

Discussion in 'Scripting' started by ivyroxy, Mar 24, 2015.

  1. ivyroxy

    ivyroxy

    Joined:
    Mar 23, 2015
    Posts:
    38
    I'm working on a project HERE.

    My question is this: how would I approach modding a game I made?

    I would like to make something along the lines of Kerbal Space Program. A second application that allows you to import a 3D model, a texture and edit it's properties. Then, export it and use it in the actual game.

    I'm not sure where to start... All help appreciated :)
     
  2. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    Hmmmm good question. I've thought about this myself.

    Since unity allows you to create a runtime that imports asset-bundles to change the content of your game from what's stored in the executable, I think one good way would be to create a dll/plugin/unity-package that you can import into unity and use unity as the actual authoring tool to create your mods, which are actually just asset bundles that the game imports itself.

    This is a high level/conjectural answer, but I'm imagining it would go something like this:
    • SimsModPrereq.dll
    This is a dll that would hold only the game code that is relevent to modding.
    For example, if you have a base abstract class, Character.cs, which your game uses as a base class to make sim characters, you could include it in the ModPrereq so modders could write character classes as well.
    • SimEditor.dll
    This would hold all of the editor functionality like adding menu items to unity to allow you to export asset-bundles, verify the content created by modders and what have you. (It needs to be separate from SimsModPrereq due to unity dll import limitations - Unity can't use an imported dll that has both engine and editor references in it. Can't remember why)

    And then a prefabs/example scenes folder, for creating scenes with objects familiar to your game, or reskinning existing objects or what have you.

    For this to work, I think it would depend heavily on writing good editor functionality to limit/guide modders to create scenes and content that works with your game specifically. Good knowledge of how to create gizmos and editor windows, and whatnot.


    What does everyone else think? I'm interested in modding functionality for my own big project.
     
  3. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    As for KSP, there are two sides to it: Models, and code. The models are usually done in Blender, Maya, and what have you, then imported into Unity, and exported again using a special KSP plugin for Unity. Code, on the other hand, is usually done completely outside of Unity. You just reference the UnityEngine.dll and KSP's Assembly-CSharp.dll in your project, and you're good to go.

    So, it kind of depends a little on what mods you are planning to allow.
     
  4. ivyroxy

    ivyroxy

    Joined:
    Mar 23, 2015
    Posts:
    38
    I want the core game to work normally on Unity, but I want every added function (i.e. Furniture, Clothes, etc...) to be a mod. Basically, anything can be added / removed / modified.
     
  5. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    The high-level answer to your general question is "use data-driven content".

    For example, if your game includes a gun with fields like "range" and "damage", then while you could put a "gun" object in your scene and set its "range" and "damage" properties from the Unity inspector, you should instead have some sort of data file that your game reads and parses at run-time that tells it what the range and damage of the gun should be. That way, you can change the range and damage just by editing the data file, without going through Unity at all (or requiring a rebuild).

    Extrapolate that idea to cover every parameter that you want people to be able to change, and you now have a moddable game.

    If you want to get fancy, you can make a second program that's designed specifically to help people edit the data file, but for simple stuff you can just use a text encoding (such as JSON) and people will (with sufficient dedication) be able to make mods for your game using just a text editor.

    BenZed offers an interesting suggestion where basically your data format is "unity asset bundles" and the editor you make to help people create mods is "a modded version of Unity". I'm not sufficiently familiar with asset bundles to offer a technical opinion on that approach, but in addition to any technical issues, you should investigate possible licensing issues (e.g. I think the license terms forbid combining content made with Unity Pro and Unity Personal, so if you are using Unity Pro, then your modders may technically also need a Unity Pro license if they're using Unity to create mods for your game).
     
  6. ivyroxy

    ivyroxy

    Joined:
    Mar 23, 2015
    Posts:
    38
  7. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Could take a data driven approach, have your game get most of its values from json or XML files instead of from the inspector or code. Also you could implement python or lua interpreter into your game and expose your own api to it.
     
  8. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    This is basically what we do. Although we tried IronPython and the performance was absolute crap so we went the route of making people write C# and compile it to a DLL.
     
  9. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Ya I never tried ironpython in unity, just mentioned it and lua since they are small interpreters that are easy to intetergrate with other products.

    The DLL idea is a good one, bit more barrier of entry though vs just editing a lua or py file and restarting the game. Since that would require the user get visual studio and know how to compile DLLs.
     
  10. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Yup. It's not the route I wanted to go but the base game suffered too much to justify the other approach.