Mod System Overview
Overview
ModSystem is a plugin for Godot 4 that provides a framework for extending and modifying game functionality through mods.
Important notes
- This plugin is not production-ready yet. It is still unfinished and many parts are still untested.
- I am using the latest Godot version at all times in development. I can't guarantee backwards-compatibility at this time, but that is a goal for the future.
Features
This plugin offers several key features for game developers:
Mod Loading: The
ModLoader
class handles the loading of mods from the file system. It scans specified mod directories, identifies mod files (e.g.,.mod.tres
or.mod.json
), and prepares them for registration.Mod Registration: The
ModClassDB
class is responsible for registering classes within the system. It tracks classes that should be available to mods. Classes are registered with unique identifiers.Mod Management: The
ModSystem
class serves as the central hub for managing mods. It provides methods for enabling, disabling, and controlling mod execution. It also allows access to an instance of theModSettings
class, which stores user preferences related to mod management.Mod Scripting: The
ModScript
class extends the nativeGDScript
class, providing automatic class registration intoModClassDB
.ModInstanceScript
provides many virtual functions to override in Mods to affect gameplay.Resource Sharing: The
ModAsset
class enables modders to share resources among instances of the same mod. Mod assets provide an organized and accessible way to load and use resources such as textures, sounds, or data files.
The Lifecycle of a Mod
Mod Loading: The
ModLoader
scans designated mod directories, identifies mod files, and loads them into memory using the appropriate format (e.g.,.mod.tres
or.mod.json
).Mod Registration: The
ModLoader
communicates with theModSystem
to register the loaded mods. This step makes the mods available within the game's runtime environment.Mod Enabling: The
ModSystem
enables or disables mods based on user preferences stored in theModSettings
. Enabled mods are ready for execution.Mod Granting: The
ModSystem
grants mods to in-game objects, allowing them to access and modify game functionality as defined by the modder.Mod Execution: The
ModInstance
class handles execution of a mod. This class instantiates a newModInstanceScript
that connects to various in-game hooks.Mod Revoking and Disabling: The
ModSystem
can revoke and disable mods, providing a mechanism for controlling the behavior and impact of mods in the game.
Implementation
From a Game Developer's Perspective
This is just a quick overview on how to implement the ModSystem plugin. For more detail, check out the tutorial (COMING SOON).
Include the Mod System plugin in your Godot project.
Set up the
ModLoader
to scan and load mod files from designated directories during the game's initialization phase by updating your game'sProjectSettings
.Use the
ModClassDB
to register any class that you want extensible by mods. Ensure that each class has a unique identifier for seamless integration.Implement the
ModSystem
to manage mod enabling, disabling, and granting. Utilize theModSettings
resource to store user preferences related to mod management.Use the
ModSystem
to to instantiate and execute enabled mods within the game.
From a Modder's Perspective
This is just a quick overview on how to create a mod. For more detail, check out the tutorial (COMING SOON).
Develop your mod functionality using GDScript.
Package your mod as a mod file (e.g.,
.mod.tres
or.mod.json
). Ensure that the file adheres to the mod file format requirements.Install your mod file in the designated mod directory specified by the game developer. This directory is scanned by the
ModLoader
during runtime.Test your mod by enabling it in-game and verifying its behavior within the game.
Class Documentation
- Singletons - Singletons created when your game starts.
- ModClassDB - Registers classes to be extensible by mods.
- ModLoader - Handles loading mods from the file system.
- ModSystem - Manages mod enabling, disabling, and granting.
- Resources - Data and asset classes.
- ModAsset - Stores a key and asset pair.
- ModInstanceScript - Main script run upon granting a mod.
- ModInstance - An instance of a mod after it's granted to an in-game object.
- ModScript - Extension of native GDScript class that registers itself to ModClassDB.
- ModSettings - Stores user preferences related to mod management.
- Mod - Defines a mod's metadata, assets, and behavior.
- RegisteredClass - Represents a class registered in ModClassDB.
- Utilities - Utility & library classes.
- ModContentLoader - Content loading utilities.
- ModPath - File system path utilities.
- ModScriptParser - GDScript parsing utilities.
- ModSystemLogger - Logging utilities.
- ModSystemProjectSettings - Project settings utilities.
- ModZipReader - ZIP reading utilities.