Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

MLGodotKit

An asset by IHunter
The page banner background of a mountain and forest
MLGodotKit hero image

Quick Information

0 ratings
MLGodotKit icon image
IHunter
MLGodotKit

MLGodotKit is a lightweight machine learning toolkit for Godot, designed specifically for game developers. It introduces new node classes through C++ bindings, enabling in-engine training and inference for simple models. Currently supported models include a Linear Regression node for basic numerical predictions, a Classification Tree node for rule-based decision making, and a Neural Network node for nonlinear classification using ReLU and Sigmoid activations. This extension is ideal for prototyping, educational projects, and integrating simple machine learning behavior directly into your Godot scenes.

Supported Engine Version
4.4
Version String
v1.0.0-exp
License Version
MIT
Support Level
community
Modified Date
2 months ago
Git URL
Issue URL

MLGodotKit

Empower your Godot projects with the power of machine learning!
MLGodotKit is a C++ GDExtension for Godot, enabling seamless integration of AI-driven features into your games and applications. With support for adaptive behaviors and real-time decision-making, it’s designed to inspire innovation and enhance gameplay.

MLGodotKit Logo


Node Extensions in Progress

  • Data Science Tooling: Tools for preprocessing, analyzing, and visualizing data directly in Godot.
  • Deep Learning Integration: Simplified nodes for building and deploying neural networks.
  • Cross-Platform Compatibility: Fully supported on Windows, Linux, and macOS.

LIMITATIONS

Please note that this is a work in process pet project of mine and as such will come with a few bugs. If you enjoy the project and want to support please open an issue for desired features or bug fixes!

Next Features to be added:

  • A linear layer for the Neural Network Model for regression based predictons
  • A robust collection of popular loss functions for out of the box use cases
  • More supervised and unsupervised model implementations
  • If you'd like to see something else add an issue!

Getting Started

Here are quick examples of how to use the three core models in MLGodotKit:

All models are GDExtension nodes and can be used directly in any Godot scene or script.


Linear Regression (LRNode)

@onready var lr_model = LRNode.new()

func _ready():
    lr_model.set_learning_rate(0.01)
    lr_model.initialize(1)

    # Simple linear dataset: y = 3x + 5
    var inputs = [[1], [2], [3]]
    var targets = [[8], [11], [14]]

    lr_model.train(inputs, targets, 1000)

    var prediction = lr_model.predict([4])
    print("Predicted y for x=4:", prediction)

Descision Tree Classifier (DTreeNode)

@onready var tree = DTreeNode.new()

func _ready():
    tree.set_max_depth(5)
    tree.fit([[1], [2], [3], [10], [11], [12]], [0, 0, 0, 1, 1, 1])

    var result = tree.predict([[2], [11]])
    print("Predictions:", result)  # [0, 1]

Neural Network (NNNode)

Note: All loss functions are left to the user to implement please see examples for suggested implementation will be implemented natively at a later date.

@onready var nn = NNNode.new()

func _ready():
    nn.set_learning_rate(0.1)
    nn.add_layer(2, 4, "relu")
    nn.add_layer(4, 1, "sigmoid")

    var inputs = [[0,0], [0,1], [1,0], [1,1]]
    var targets = [[0], [1], [1], [0]]  # XOR logic

    for i in range(5000):
        for j in range(inputs.size()):
            var y_pred = nn.forward([inputs[j]])[0]
            var error = y_pred - targets[j][0]
            nn.backward([[2.0 * error]])

    print("Test XOR:")
    for i in range(inputs.size()):
        var output = nn.forward([inputs[i]])
        print("Input:", inputs[i], " Predicted:", output, "Expected:", targets[i])

Credits

Built on the powerful Eigen C++ library.

MLGodotKit is a lightweight machine learning toolkit for Godot, designed specifically for game developers. It introduces new node classes through C++ bindings, enabling in-engine training and inference for simple models. Currently supported models include a Linear Regression node for basic numerical predictions, a Classification Tree node for rule-based decision making, and a Neural Network node for nonlinear classification using ReLU and Sigmoid activations. This extension is ideal for prototyping, educational projects, and integrating simple machine learning behavior directly into your Godot scenes.

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
MLGodotKit icon image
IHunter
MLGodotKit

MLGodotKit is a lightweight machine learning toolkit for Godot, designed specifically for game developers. It introduces new node classes through C++ bindings, enabling in-engine training and inference for simple models. Currently supported models include a Linear Regression node for basic numerical predictions, a Classification Tree node for rule-based decision making, and a Neural Network node for nonlinear classification using ReLU and Sigmoid activations. This extension is ideal for prototyping, educational projects, and integrating simple machine learning behavior directly into your Godot scenes.

Supported Engine Version
4.4
Version String
v1.0.0-exp
License Version
MIT
Support Level
community
Modified Date
2 months ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers