home / skills / a5c-ai / babysitter / godot-csharp

This skill helps you integrate C# with Godot 4, enabling efficient game logic, performance patterns, and .NET interoperability.

npx playbooks add skill a5c-ai/babysitter --skill godot-csharp

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
1.9 KB
---
name: godot-csharp
description: Godot C# programming skill for .NET integration, scripting patterns, and performance optimization.
allowed-tools: Read, Grep, Write, Bash, Edit, Glob, WebFetch
---

# Godot C# Skill

C# programming for Godot Engine development.

## Overview

This skill provides capabilities for implementing game logic using C# in Godot, leveraging .NET integration.

## Capabilities

### C# Integration
- Node class inheritance
- Attribute-based exports
- Signal definitions
- Callable system

### .NET Features
- NuGet packages
- Async/await patterns
- LINQ queries
- .NET libraries

### Interoperability
- Call GDScript from C#
- Expose to GDScript
- Handle Variant types
- Manage signals

### Performance
- Struct usage
- Memory management
- Object pooling
- Span usage

## Prerequisites

- Godot 4.0+ with .NET support
- .NET SDK installed
- C# IDE (VS Code, Rider)

## Usage Patterns

### Node Script

```csharp
using Godot;

public partial class Player : CharacterBody2D
{
    [Export]
    public float Speed { get; set; } = 200f;

    [Signal]
    public delegate void HealthChangedEventHandler(int newHealth);

    private int _health = 100;

    public override void _Ready()
    {
        // Initialize
    }

    public override void _PhysicsProcess(double delta)
    {
        var velocity = Vector2.Zero;
        velocity.X = Input.GetAxis("move_left", "move_right");
        velocity.Y = Input.GetAxis("move_up", "move_down");
        Velocity = velocity.Normalized() * Speed;
        MoveAndSlide();
    }
}
```

### Signal Connection

```csharp
button.Pressed += OnButtonPressed;
// or
button.Connect("pressed", Callable.From(OnButtonPressed));
```

## Best Practices

1. Use partial classes
2. Leverage NuGet packages
3. Handle node lifecycle
4. Profile memory usage
5. Use source generators

## References

- [Godot C# Documentation](https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/)

Overview

This skill teaches Godot C# development for .NET-enabled Godot projects, focusing on integration, scripting patterns, and performance optimization. It covers node scripting, signals, interoperability with GDScript, and practical .NET features for game code. The content targets Godot 4+ with .NET support and common C# workflows used in game production.

How this skill works

It inspects and guides C# scripts that inherit Godot node types, showing attribute-based exports, signal declarations, and callable patterns. It highlights .NET features such as async/await, LINQ, and NuGet usage, and explains how to interoperate with GDScript and Godot Variant types. It also reviews performance techniques like struct usage, object pooling, Span usage, and memory profiling.

When to use it

  • When writing game logic for Godot 4+ using C# and .NET.
  • When you need to call between C# and GDScript or expose C# APIs to scenes.
  • When optimizing memory, CPU, or garbage collection pressure in gameplay code.
  • When integrating third-party .NET libraries via NuGet into a Godot project.
  • When establishing signal/event patterns and lifecycle management for nodes.

Best practices

  • Use partial classes and clear node inheritance to separate generated and hand-written code.
  • Prefer attribute-based [Export] fields for editor-tunable values and typed signals for safe events.
  • Manage node lifecycle explicitly: attach in _Ready, clean up in _ExitTree, and avoid heavy allocations in _PhysicsProcess.
  • Profile memory and allocate pools for frequently spawned objects; prefer structs or Span for hot paths.
  • Use async/await for IO and background tasks, but keep Unity-like frame-critical work synchronous.

Example use cases

  • Implementing a CharacterBody2D controller with Exported tuning parameters and typed signals.
  • Connecting UI buttons from C# using event handlers or Callable.From for decoupled responses.
  • Integrating a NuGet library for pathfinding or serialization and exposing its API to scenes.
  • Reducing GC stalls by pooling bullet or particle objects and using structs for small data packets.
  • Calling GDScript utilities from C# or exposing C# services to existing GDScript code.

FAQ

What Godot and .NET versions are required?

Use Godot 4.0 or later with .NET support and a matching .NET SDK installed.

Can I use NuGet packages in Godot C# projects?

Yes. Add packages to your project file and ensure they are compatible with the target .NET runtime used by Godot.