Skip to content

Creating your first mod

DipCrai edited this page Jun 27, 2024 · 10 revisions

Setting up your project

  • Open WorldBox directory
  • Open or create folder named Mods
  • Create folder with your project name
  • Create mod.json file and paste this template into it
{
  "ModName": "",
  "Author": "",
  "Description": "",
  "Version": "",
  "Scripts": [],
  "EntryPoint": ""
}
  • In field called ModName enter the name of your mod
  • In field called Author enter author name of your mod
  • In field called Description enter description of your mod
  • In field called Version enter version of your mod
  • In field called Scripts list all files in your mod directory with extension .cs

Example: "Scripts": [ "AAA.cs", "BBB.cs", "CCC.cs", "Folder name\\ScriptName.cs" ]

Make sure that \ is replaced with \\, otherwise the game will throw an error. Or use / instead of \

  • In filed called EntryPoint enter name of class that contains method called Main

Example "EntryPoint": "NamespaceName.ClassName"

You can also create folder called dependencies that contains your mod dependencies (dll files)

Here is an example of the file that should result in the end:

{
  "ModName": "Sample mod",
  "Author": "DipCrai",
  "Description": "Just sample mod",
  "Version": "1.0",
  "Scripts": [ "Mod.cs", "Debugger.cs", "Utils.cs" ],
  "EntryPoint": "SampleMod.Mod"
}

Creating an entry point

  • Create file with name specified in the mod.json file
  • Add necessary usings
  • Create namespace with namespace name specified in the mod.json file (NamespaceName.ClassName)
  • Add class with class name specified in the mod.json file (NamespaceName.ClassName)
  • In class create method called Main

After this steps your C# file should look like this:

using UnityEngine;

namespace NamespaceName
{
    public class ClassName
    {
        public static void Main()
        {
            //This method is the entry point. 
        }
    }
}

Here is an example of the code that should result in the end:

using UnityEngine;

namespace SampleMod
{
    public class Mod
    {
        public static void Main()
        {
            Debug.Log("Init Sample Mod");
            GameObject sampleObject = new GameObject("Sample Object");
            sampleObject.AddComponent<SampleComponent>();
        }
    }
    public class SampleComponent : MonoBehaviour
    {
        private void Start()
        {
            Debug.Log("Sample component");
        }
    }
}

Clone this wiki locally