-
Notifications
You must be signed in to change notification settings - Fork 44
ModLoaderMod
Extends: Object
This Class provides helper functions to build mods.
| Method | Description |
|---|---|
install_script_extension |
⭐ Install a script extension that extends a vanilla script. |
register_global_classes_from_array |
Register an array of classes to the global scope, since Godot only does that in the editor. |
add_translation |
⭐ Add a translation file. |
get_mod_data |
Gets the ModData from the provided namespace |
get_mod_data_all |
Gets the ModData of all loaded Mods as Dictionary. |
is_mod_loaded |
Returns true if the mod with the given mod_id was successfully loaded. |
append_node_in_scene |
Appends a new node to a modified scene. |
save_scene |
Saves a modified scene to a file. |
get_unpacked_dir |
⭐ Returns the path to the directory where unpacked mods are stored. |
func install_script_extension(child_script_path: String) -> voidInstall a script extension that extends a vanilla script. 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.
To learn more about script extensions, read: Script-Extensions
Parameters:
- child_script_path (String): The path to the mod's extender script.
Returns: void
func register_global_classes_from_array(new_global_classes: Array) -> voidRegister an array of classes to the global scope since Godot only does that in the editor.
Format: { "base": "ParentClass", "class": "ClassName", "language": "GDScript", "path": "res://path/class_name.gd" }
Note: You can find these easily in the project.godot file under _global_script_classes
(but you should only include classes belonging to your mod)
Note: Using this method create override.cfg in game directory, so any mod using it would require for player to restart game once, or it may cause crash as the elements refer by class will be inaccessible. Additionally, if you have mod uploader placed in the same location (Godot based), it will crash it.
Parameters:
- new_global_classes (Array): An array of class definitions to be registered.
Returns: void
func add_translation(resource_path: String) -> voidAdd a translation file.
Note: The translation file should have been created in Godot already,
such as when importing a CSV file. The translation file should be in the format mytranslation.en.translation.
Parameters:
- resource_path (String): The path to the translation resource file.
Returns: void
func get_mod_data(mod_id: String) -> ModDataGets the ModData from the provided namespace
Parameters:
- mod_id (String): The ID of the mod.
Returns:
- ModData: The ModData associated with the provided mod_id, or null if the mod_id is invalid.
func get_mod_data_all() -> DictionaryGets the ModData of all loaded Mods as Dictionary.
Returns:
- Dictionary: A dictionary containing the ModData of all loaded mods.
func is_mod_loaded(mod_id: String) -> boolReturns 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.
func append_node_in_scene(modified_scene: Node, node_name: String = "", node_parent = null, instance_path: String = "", is_visible: bool = true) -> voidAppends a new node to a modified scene.
Parameters:
- modified_scene (Node): The modified scene where the node will be appended.
- node_name (String): (Optional) The name of the new node. Default is an empty string.
- node_parent (Node): (Optional) The parent node where the new node will be added. Default is null (direct child of modified_scene).
- instance_path (String): (Optional) The path to a scene resource that will be instantiated as the new node.
Default is an empty string resulting in a
Nodeinstance. - is_visible (bool): (Optional) If true, the new node will be visible. Default is true.
Returns: void
func save_scene(modified_scene: Node, scene_path: String) -> voidSaves a modified scene to a file.
Parameters:
- modified_scene (Node): The modified scene instance to be saved.
- scene_path (String): The path to the scene file that will be replaced.
Returns: void
func get_unpacked_dir() -> StringReturns the path to the directory where unpacked mods are stored.
Returns:
- String: The path to the unpacked mods directory.
const LOG_NAME: String = "ModLoader:Mod"Warning
This documentation has moved!
You can find it here: https://wiki.godotmodding.com/
- Home
- Getting Started
- ModLoader API
- Reference
- Guides
- Versions & Releases