5 releases

new 0.2.1 Dec 8, 2024
0.2.0 Nov 15, 2024
0.1.3 Jul 22, 2024
0.1.1 Jun 24, 2024
0.1.0 May 30, 2016

#63 in Game dev

Download history 177/week @ 2024-08-19 140/week @ 2024-08-26 130/week @ 2024-09-02 119/week @ 2024-09-09 130/week @ 2024-09-16 202/week @ 2024-09-23 176/week @ 2024-09-30 103/week @ 2024-10-07 289/week @ 2024-10-14 333/week @ 2024-10-21 119/week @ 2024-10-28 224/week @ 2024-11-04 355/week @ 2024-11-11 312/week @ 2024-11-18 460/week @ 2024-11-25 333/week @ 2024-12-02

1,477 downloads per month
Used in 6 crates

MPL-2.0 license

1MB
20K SLoC

logo.png

Rust bindings for Godot 4

Website | GitHub | Book | API Docs | Discord | Mastodon | Twitter | Sponsor

The godot crate integrates the Rust language with Godot 4.

Godot is an open-source game engine, focusing on a productive and batteries-included 2D and 3D experience.
Its GDExtension API allows integrating third-party languages and libraries.

Philosophy

The Rust binding is an alternative to GDScript, with a focus on type safety, scalability and performance.

The primary goal of this library is to provide a pragmatic Rust API for game developers. Recurring workflows should be simple and require minimal boilerplate. APIs are designed to be safe and idiomatic Rust wherever possible. Due to interacting with Godot as a C++ engine, we sometimes follow unconventional approaches to provide a good user experience.

Example

The following code snippet demonstrates writing a simple Godot class Player in Rust.

use godot::prelude::*;
use godot::classes::{ISprite2D, Sprite2D};

// Declare the Player class inheriting Sprite2D.
#[derive(GodotClass)]
#[class(base=Sprite2D)]
struct Player {
    // Inheritance via composition: access to Sprite2D methods.
    base: Base<Sprite2D>,

    // Other fields.
    velocity: Vector2,
    hitpoints: i32,
}

// Implement Godot's virtual methods via predefined trait.
#[godot_api]
impl ISprite2D for Player {
    // Default constructor (base object is passed in).
    fn init(base: Base<Sprite2D>) -> Self {
        Player {
            base,
            velocity: Vector2::ZERO,
            hitpoints: 100,
        }
    }

    // Override the `_ready` method.
    fn ready(&mut self) {
        godot_print!("Player ready!");
    }
}

// Implement custom methods that can be called from GDScript.
#[godot_api]
impl Player {
    #[func]
    fn take_damage(&mut self, damage: i32) {
        self.hitpoints -= damage;
        godot_print!("Player hit! HP left: {}", self.hitpoints);
    }
}

More

For more information, check out our Website or GitHub page!

Dependencies

~4–6MB
~155K SLoC