Skip to content

Global Classes & Child Nodes

Darkly77 edited this page Jun 21, 2023 · 1 revision

This page covers advanced techniques for mod making.

Global Classes

ModLoader can't support global classes, because they're registered in a settings file stored inside the binary itself. This means that you can't expose a global class for other dependent mods to use. However, you can work around this limitation by exposing the class as a child node (see below).

Child Nodes

When your mod is initialised it's added as a child to the ModLoader node (shown left). You can also add additional child nodes to your mod's node if you wish (shown right):

scene-tree scene-tree-child

This lets you make custom classes available to other mods.

Examples

Example for adding a child node in mod_main.gd. This particular example comes from Brotato's ContentLoader mod:

# Add to your mod's `_init` in mod_main.gd
func _add_child_class():
	var ContentLoader = load("res://mods-unpacked/Darkly77-ContentLoader/content_loader.gd").new()
	ContentLoader.name = "ContentLoader"
	add_child(ContentLoader)

To use this in a different mod:

# Get the class
var ContentLoader = get_node("/root/ModLoader/Darkly77-ContentLoader/ContentLoader")

# Use a method from the class
ContentLoader.load_data()