Skip to main content

ModClassDB

See the code at autoload/mod_class_db.gd

Description

Inherits Node

The ModClassDB class is a singleton that serves as a database of all classes registered to the Mod System. It provides methods for registering classes, unregistering classes, and querying registered classes.

This class allows the Mod System to keep track of classes that can be extended, modified, or referenced by mods.

Game developers who want their classes to be modifiable through the Mod System need to ensure that they register their classes with the ModClassDB so that mods can interact with them.


Signals

class_registered

signal class_registered(cls: RegisteredClass)

This signal is emitted when a class is registered to ModClassDB.

Parameters

NameTypeDescription
clsRegisteredClassThe just-registered class.

class_unregistered

signal class_unregistered(cls: RegisteredClass)

This signal is emitted when a class is unregistered from ModClassDB.

Parameters

NameTypeDescription
clsRegisteredClassThe just-unregistered class.

Properties

registered_classes

var registered_classes: Array[RegisteredClass]

An array that holds the current registered classes.

TypeArray[RegisteredClass]
Default[]

Methods

register

func register(script: GDScript) -> RegisteredClass

Registers a class to ModClassDB, enabling use in the Mod System.

This method creates a RegisteredClass object for the class and adds it to the registered_classes array. The class_registered signal is emitted after registration.

Parameters

NameTypeDescription
clsGDscriptThe script of the class to register.

Returns

TypeRegisteredClass
DescriptionThe just-registered class.

register_with_name

func register_with_name(cls: StringName, script: GDScript) -> RegisteredClass

Registers a class to ModClassDB with the given name, enabling use in the Mod System.

This method creates a RegisteredClass object for the class and adds it to the registered_classes array. The class_registered signal is emitted after registration.

Parameters

NameTypeDescription
clsStringNameThe name to use when registering the class. See RegisteredClass.name.
scriptGDscriptThe script of the class to register.

Returns

TypeRegisteredClass
DescriptionThe just-registered class.

unregister

func unregister(cls: StringName) -> void

Unregisters a class from ModClassDB, disabling use in the Mod System.

This method removes the corresponding RegisteredClass object from the registered_classes array. The class_unregistered signal is emitted after unregistration.

Parameters

NameTypeDescription
clsStringNameThe name of the class to unregister.

is_class_name_registered

func is_class_name_registered(cls: StringName) -> bool

Checks if a class name is registered with ModClassDB.

This method searches the registered_classes array for a matching class name and returns the result.

Parameters

NameTypeDescription
clsStringNameThe name of the class to check.

Returns

Typebool
Descriptiontrue if the class name is registered, false otherwise

is_script_registered

func is_script_registered(cls: Script) -> bool

Checks if a script is registered with ModClassDB.

This method searches the registered_classes array for a matching script and returns the result.

Parameters

NameTypeDescription
clsScriptThe script to check.

Returns

Typebool
Descriptiontrue if the script class is registered, false otherwise

get_by_name

func get_by_name(cls: StringName) -> RegisteredClass

Retrieves a registered class by its name.

This method searches the registered_classes array for a matching class name and returns the corresponding RegisteredClass object.

Parameters

NameTypeDescription
clsStringNameThe name of the class to retrieve.

Returns

TypeRegisteredClass
DescriptionThe registered class.

get_by_script

func get_by_script(cls: Script) -> RegisteredClass

Retrieves a registered class by its script.

This method searches the registered_classes array for a matching script and returns the corresponding RegisteredClass object.

Parameters

NameTypeDescription
clsScriptThe script to retrieve.

Returns

TypeRegisteredClass
DescriptionThe registered class.