Making a moddable game


After spending 6 or so months working my RPG game Twilight Haven I discovered important things that many developers should take into account:

  • Unity editor gets slower and buggier the bigger your game gets. I got sick of the reloads and and Unity editor lock ups where I had to not only force shut down my editor but Visual Studio as well.
  • The need to change things within your game without having to go through the slow process of redeploying a build

I have worked with various modding systems before in the past so I decided to put a full pause on my games development and rewrite it so that it can be modded. For this I needed to:

  • Consolidate my resources (namely sprites, textures and prefabs)
  • Tabulate much of my game using a text format, this makes it easy for me to change the game whilst its running and / or without having to make a new build
  • Provide a scripting system to allow game logic to be added via a scripting language that doesn't need to be compiled

So I set about searching for solutions and decided on the following:

  • JSON – I've been using this for decades and its almost always been my go to, I did go through a phase where I was just XML but ended up back at JSON
  • Lua – I've used Lua many times in the past so very familiar with it, especially as I have recently been working on Roblox games with an old friend so its fresh in my mind

In the end I tabulating various areas of the game into these tables:

  • AnimalsTable.json – Lists all animals within the game and their attributes
  • ArtifactsTable.json – Lists all artefacts within the game and their attributes
  • BlueprintsTable.json – Lists all crafting blueprints within the game and their attributes
  • BooksTable.json – Lists all books within the game and their attributes
  • BuffsTable.json – Lists all buffs within the game and their attributes
  • CharactersTable.json – Lists all characters within the game and their attributes such as birthdays, gift items etc..
  • CookingTable.json – Lists all cooking recipes within the game and their attributes such as ingredients, cook times etc..
  • CropsTable.json – Lists all crops within the game and their attributes such as growth rates
  • CursesTable.json – Lists all curses within the game and their attributes
  • DecorItemsTable.json – Lists all décor items within the game and their attributes
  • InventoryTable.json – Lists all possible inventory within the game and their attributes including worth, drop rate, fishing chance etc..
  • MonstersTable.json – Lists all mobs within the game and their attributes
  • QuestsTable.json – Lists all quests within the game and their attributes
  • SpriteTable.json – Lists all sprites within the game and their attributes
  • StringsTable.json – Lists all text within the game
  • VendorsTable.json – Lists all vendors and their wares within the game and their attributes

There are also a extension tables available in the StreamingAssets folder which can be used to modify to these tables, allowing users to extend the game

Much of the internals of the game is also accessible from Lua, allowing me to access just about anything within the game from Lua. You can access the main Singleton within the game called Archon and access many of the systems within the world and UI from Lua. Lua is plugged into many of the systems via call backs, for example when the player touches something it calls Lua if it has registered a call back to listen to it.

Below is part of the code that is used to generate the mobs within a mine room:


Now I have this system in place, making adjustments to the game is far less painful. I do need to extend the system to tabulate the game world, at the moment its a large map broken into sectors, its difficult making changes as Unity decides it wants to just sit there for a few minutes whilst I twiddle my thumbs. In Unity's defence the game world is quite large already and its not even half done

Leave a comment

Log in with itch.io to leave a comment.