Godot plugin that registers custom C# resources & nodes.
NOTE: This is for Godot 4.x. If you are using Godot 3.x please refer to the godot-3.x branch.
This is a Godot C# plugin that registers custom C# resources and custom nodes for Godot 4.x. This plugin serves as a workaround for the Godot engine’s C# resource missing in context menu issue. Once C# resource exports gets merged into the engine, this plugin may no longer be necessary.
Based off of CustomResourceRegisterPlugin made by wmigor
using MonoCustomResourceRegistry;
to the top of your file to import this plugin’s namespace, which contains RegisteredTypeAttribute
.Anytime the Plugin registers/unregisters a resource/node, the plugin will print its actions into the Output window.
[RegisteredType(string name, string iconPath = "", string baseType = ""))]
Sample usage:
// Inside a file named CustomNodeDemo.cs
using MonoCustomResourceRegistry;
// Registers a custom type with
// a name of "CustomNodeDemo",
// an icon located at "res://custom_icon.png",
// and a base type of "Node2D"
[RegisteredType(nameof(CustomNodeDemo), "res://custom_icon.png", nameof(Node2D))]
public class CustomNodeDemo : Node2D
{
...
}
// Inside a file named CustomNodeDemo2.cs
using MonoCustomResourceRegistry;
// Registers a custom type with
// a name of "CustomNodeDemo",
// no icon,
// and a base type of "Button"
[RegisteredType(nameof(CustomNodeDemo), "", nameof(Button))]
public class CustomNodeDemo2 : Button
{
...
}
// Inside a file named CustomNodeDemo3.cs
using MonoCustomResourceRegistry;
// Registers a custom type with
// a name of "CustomNodeDemo",
// no icon,
// and a default base type of "Resource"
[RegisteredType(nameof(CustomNodeDemo))]
public class CustomNodeDemo3 : Resource
{
...
}
This plugin comes with some settings to configure how C# resources are loaded.
The settings can be accessed by going to Project > Project Settings > General > Mono Custom Resource Registry.
If you can’t see the settings, make sure Advanced Settings
is toggled on. You can find Advanced Settings
on
the top right corner of the Project Settings window.
All settings are listed below:
Class Prefix - The prefix that is seen before all custom nodes and resources.
Resource Script Directories - The paths to the directories where you want to scan for C# resource scripts to register as custom resources. By default, it only contains “res://“.
Search Type - The method used to gather custom C# resource scripts.
Namespace - Looks for scripts by using their namespace as a directory.
For example with the C# script below, the plugin will look under each resource script directory for the script by using the path “./Some/Long/Namespace/Something.cs”.
namespace Some.Long.Namespace
{
public class Something : Resource
{
}
}
Recursive - Looks for scripts by searching through all “Resource Script Directories” and the directories within them.