Description
Changelog
Reviews (0)

DotGodot

DotGodot is a C# Source Generator plugin for Godot 4 that provides zero-cost, compile-time code generation to eliminate boilerplate in C# game scripts.

💡 Features

  • [OnReady] Auto Node Binding: Mark fields/properties with [OnReady] and GetNode<T>() is injected at compile time. No manual _Ready() wiring.
  • [OnSignal] Auto Signal Connection: Annotate methods with [OnSignal("signal_name", "NodePath")] and the connection code is generated at compile time. No manual Connect() calls.
  • Zero Runtime Overhead: All code is generated at compile time via Roslyn Source Generators. No reflection, no runtime cost.
  • Clean Code: Reduces boilerplate code in the _Ready() method.

📝 Quick Start / Usage

Here is a simple example of how to use the [OnReady] attribute in your C# scripts:

using Godot;
using DotGodot; // Importing the namespace

public partial class Player : Node2D
{
    // ---- [OnReady] Demo ----
    [OnReady] private Sprite2D _sprite = null!; // Automatically binds the node named 'Sprite'

    [OnReady("%AnimationPlayer")] // Also supports '%' (Scene Unique Node) binding
    public AnimationPlayer AnimPlayer { get; private set; } = null!; // Supports properties

    // ---- [OnSignal] Demo ----
    [OnSignal("animation_finished", "%AnimationPlayer")]
    private void OnAnimationFinished(StringName animName)
    {
        GD.Print($"Animation finished: {animName}");
    }

    [OnSignal("pressed", "%SubmitButton")]
    private void OnSubmitPressed()
    {
        GD.Print("Submit clicked via Connect fallback!");
    }
    // ----

    public override void _Ready()
    {
        GD.Print("Sprite bound successfully: ", _sprite != null);
        GD.Print("AnimationPlayer bound successfully: ", AnimPlayer != null);
    }

    public partial class MoveState : Node // Supports nested classes
    {
        [OnReady("../AnimationPlayer")] // Uses relative path
        private AnimationPlayer _anim = null!;
    }
}

🔨 Installation

  1. Download the asset or clone the repository.
  2. Copy the addons/dotgodot folder into your project's addons/ directory.
  3. Add the following lines to your project's .csproj file to reference the required generator targets and configure additional files:
<!-- Add this inside the <Project> tag of your GameProject.csproj -->
<Import Project="addons\dotgodot\data\dotgodot.targets" />
  1. Rebuild your C# project in Godot.
  2. Go to Project -> Project Settings -> Plugins and enable DotGodot.

🤖 For AI Assistants

This package includes addons/dotgodot/data/.cursor/rules/dotgodot.mdc — an AI-readable rule file that teaches Cursor how to use DotGodot. Copy it to your project's .cursor/rules/ directory for AI-assisted coding, or run one of these commands in the project root:

# Windows (cmd)
mkdir .cursor\rules\ 2>nul & copy addons\dotgodot\data\.cursor\rules\dotgodot.mdc .cursor\rules\
# Linux / macOS
mkdir -p .cursor/rules/ && cp addons/dotgodot/data/.cursor/rules/dotgodot.mdc .cursor/rules/

💪 Future Plans

More C# quality-of-life utilities are planned for future updates. Feedback and contributions are highly welcome!

Changelog for version v0.1

No changelog provided for this version.

Reviews

DotGodot has no reviews yet.

Login to write a review.