ModLoaderMod🔗
Inherits: Object
This Class provides helper functions to build mods.
Constants🔗
• LOG_NAME
: "ModLoader:Mod"
🔗
Method Descriptions🔗
• void install_script_extension(child_script_path: String)
static🔗
Description:🔗
Installs a script extension that extends a vanilla script.
Parameters:🔗
child_script_path
(String
): The path to the mod's extender script.
Returns:
- No return value
This is the preferred way of modifying a vanilla Script
Since Godot 4, extensions can cause issues with scripts that use class_name
and should be avoided if present.
See add_hook()
for those cases.
The child_script_path
should point to your mod's extender script.
Example: "MOD/extensions/singletons/utils.gd"
Inside the extender script, include extends {target}
where {target}
is the vanilla path.
Example: extends "res://singletons/utils.gd"
.
Note
Your extender script doesn't have to follow the same directory path as the vanilla file, but it's good practice to do so.
• void install_script_hooks(vanilla_script_path: String, hook_script_path: String)
static🔗
Description:🔗
Adds all methods from a file as hooks.
Parameters:🔗
vanilla_script_path
(String
): The path to the script which will be hooked.hook_script_path
(String
): The path to the script containing hooks.
Returns:
- No return value
The file needs to extend Object
.
The methods in the file need to have the exact same name as the vanilla method they intend to hook, all mismatches will be ignored.
See: add_hook()
Examples:🔗
GDScript | |
---|---|
• void add_hook(mod_callable: Callable, script_path: String, method_name: String)
static🔗
Description:🔗
Adds a hook, a custom mod function, to a vanilla method.
Parameters:🔗
mod_callable
(Callable
): The function that will executed when the vanilla method is executed. When writing a mod callable, make sure that it always receives aModLoaderHookChain
object as first argument, which is used to continue down the hook chain (see:ModLoaderHookChain.execute_next()
) and allows manipulating parameters before and return values after the vanilla method is called.script_path
(String
): Path to the vanilla script that holds the method.method_name
(String
): The method the hook will be applied to.
Returns:
- No return value
Opposed to script extensions, hooks can be applied to scripts that use class_name
without issues.
If possible, prefer install_script_extension()
.
Examples:🔗
Given the following vanilla script main.gd
GDScript | |
---|---|
mod_main.gd
like this
• void register_global_classes_from_array(new_global_classes: Array)
static🔗
Description:🔗
Registers an array of classes to the global scope since Godot only does that in the editor.
Parameters:🔗
new_global_classes
(Array
): An array of class definitions to be registered.
Returns:
- No return value
Format: { "base": "ParentClass", "class": "ClassName", "language": "GDScript", "path": "res://path/class_name.gd" }
Tip
You can find these easily in the project.godot file under _global_script_classes
(but you should only include classes belonging to your mod)
• void add_translation(resource_path: String)
static🔗
Description:🔗
Adds a translation file.
Parameters:🔗
-
resource_path
(String
): The path to the translation resource file.
Returns: -
No return value
Note
The .translation
file should have been created by the Godot editor already, usually when importing a CSV file. The translation file should named name.langcode.translation
-> mytranslation.en.translation
.
• void refresh_scene(scene_path: String)
static🔗
Description:🔗
Marks the given scene for to be refreshed. It will be refreshed at the correct point in time later.
Parameters:🔗
-
scene_path
(String
): The path to the scene file to be refreshed.
Returns: -
No return value
Version
This function requires Godot 4.3 or higher.
This function is useful if a script extension is not automatically applied. This situation can occur when a script is attached to a preloaded scene. If you encounter issues where your script extension is not working as expected, try to identify the scene to which it is attached and use this method to refresh it. This will reload already loaded scenes and apply the script extension.
• void extend_scene(scene_vanilla_path: String, edit_callable: Callable)
static🔗
Description:🔗
Extends a specific scene by providing a callable function to modify it.
Parameters:🔗
scene_vanilla_path
(String
): The path to the vanilla scene file.edit_callable
(Callable
): The callable function to modify the scene.
Returns:
- No return value
The callable receives an instance of the "vanilla_scene" as the first parameter.
• ModData
get_mod_data(mod_id: String)
static🔗
Description:🔗
Gets the ModData
from the provided namespace.
Parameters:🔗
mod_id
(String
): The ID of the mod.
Returns:
• Dictionary
get_mod_data_all()
static🔗
Description:🔗
Gets the ModData
of all loaded Mods as Dictionary
.
Returns:
Dictionary
: A dictionary containing theModData
of all loaded mods.
• String
get_unpacked_dir()
static🔗
Description:🔗
Returns the path to the directory where unpacked mods are stored.
Returns:
String
: The path to the unpacked mods directory.
• bool
is_mod_loaded(mod_id: String)
static🔗
Description:🔗
Returns true if the mod with the given mod_id
was successfully loaded.
Parameters:🔗
mod_id
(String
): The ID of the mod.
Returns:
bool
: true if the mod is loaded, false otherwise.
• bool
is_mod_active(mod_id: String)
static🔗
Description:🔗
Returns true if the mod with the given mod_id was successfully loaded and is currently active.
Parameters: - mod_id
(String
): The ID of the mod.
Returns: - bool
: true if the mod is loaded and active, false otherwise.