Godot — Free “Mingleton” AddOn For Architecture
Video
- Introduction to the Mingleton add-on
- Overview of the installation and setup
- Demonstrating Mingleton in action with unit tests
Introduction to the Mingleton add-on
Hello and welcome to this continued series on the Godot engine! Today, we’re going to look at an add-on that I have freely available called Mingleton, a Singleton pattern for Godot. We’ll see how and why it’s useful for your game development. My name is Samuel Asher Rello, a game developer with over 20 years of experience, focusing primarily on the Unity game engine for the past decade. I’ve shipped titles for PC, Steam, Xbox, iOS, Android, and more. Alongside commercial development, I create educational materials around game development. Historically, these materials focus on Unity, but I’m doing more with Godot and loving it.
I have courses on 2D game development, UI design, and C-based courses covering topics like unit testing, MVC architecture, and physics in Unity. As I create more resources, I centralize them at my Godot portfolio. There, you can find game samples, articles, repos, my thoughts, tips on using Godot, and all the videos in this series. Whether you watch them in order or dive into specific topics, these episodic videos are designed to help you build your knowledge over time.
Overview of the installation and setup
The RMC Mingleton for Godot library is offered as a Godot plugin, accessible freely on GitHub. The idea behind Mingleton is to manage Singletons, allowing them to mingle without specific restrictions. Typically, Singleton implementations require a class to extend or implement certain interfaces. Mingleton eliminates these restrictions, offering full flexibility for your classes.
Installation steps are straightforward and listed in the readme. Ensure you bring in the RMC core library as a dependency and optionally, the GDUnit 4 library for unit testing. After downloading these libraries and dragging them into your project’s add-ons folder, enable the plugins in the project settings.
Mingleton manages your Singletons without using Godot’s autoload. This provides greater flexibility and ease of use. For example, in a fresh project, after setting up the plugins, you can see how Mingleton works through provided examples.
Demonstrating Mingleton in action with unit tests
Let’s take a look at an example of Mingleton in action. The example demonstrates creating and managing Singletons without the need for autoload.
Overview of the functionality:
- Adding a Singleton: Use `Mingleton.Instance.AddSingleton` to add a Singleton instance.
- Getting a Singleton: Use `Mingleton.Instance.GetSingleton` to retrieve the instance.
- Removing a Singleton: Use `Mingleton.Instance.RemoveSingleton` to remove the instance.
For example, consider a class `MySingleton` with a public property `Health`. By adding this class as a Singleton, you can access and modify `Health` globally across your game.
public class MySingleton
{
public float Health = 100;
}
In your game code, you can add, get, and manipulate this Singleton as needed:
// Adding the Singleton
Mingleton.Instance.AddSingleton<MySingleton>();
// Accessing the Singleton
var singleton = Mingleton.Instance.GetSingleton<MySingleton>();
singleton.Health = 100;
// Or simply add & access at the same time
Mingleton.Instance.GetOrCreateAsClass<MySingleton>();
To demonstrate the functionality, I’ve included unit tests using the GDUnit 4 plugin. Running these tests verifies that the Mingleton implementation works as expected. The tests cover various scenarios, ensuring the robustness of the Singleton management system.
By running the tests from the GDUnit console, you can see all the tests pass, providing confidence in the implementation. You can add your own unit tests to explore the API further and ensure your code’s reliability.
Resources
🦜 Contact
- Samuel Asher Rivello has over 20 years of game dev XP. He is available for remote, contract hire as a game developer and game dev educator.
- Godot Portfolio — Games, Demos, Tips & Tricks
- Contact Sam today to say hi and discuss your projects!
📜 Articles
- Godot Template Project — Start your next game with this!
- Godot — 1. Game Engine Overview — Master the fundamentals
- Godot — 2. Best Project Template — Start here
- Godot — 3. Free “Core” AddOn For Gaming — Best reusable functionality
- Godot — 4. Free “Mingleton” AddOn For Architecture — Scale your projects right