Giter Club home page Giter Club logo

bevy_godot4's Introduction

bevy_godot4

Bring the design power of Bevy's ECS to the mature engine capabilities of Godot 4.

WARNING: This crate is very early in development, and is very untested.

The architecture in this crate and most code is shamelessly taken from bevy_godot, a similar crate for working with Godot 3 and gdnative. This crate will most likely be merged back into that one at some point.

Setup

  • Follow the steps outlined in the GDExtension setup

  • Add this line to your cargo dependencies (along with the godot dependency from GDextension setup):

[dependencies]
godot = { from gdext setup }
...
bevy_godot4 = { git = "https://github.com/jrockett6/bevy_godot4", branch = "main" }
  • Create a function that takes a &mut App and builds your bevy app, and annotate it with #[bevy_app]:
#[bevy_app]
fn build_app(app: &mut App) {
    app.add_system(my_system)
        .add_system(my_other_system)
}
  • Cargo build your project, and make sure the dll is found by Godot via the .gdextension file. You should now have the BevyApp node avaiable to you in the Godot editor (though you may need to restart the editor). You can now add this BevyApp node as a Godot autoload.

Features

At it's core, this crate is just a rust Godot node holding a bevy app that you can add as an autoload (singleton) in your Godot app.

This crate also provides utilities to be able to work with Godot's systems from within the Bevy framework, such as:

Godot nodes as components

ErasedGd is a Bevy component that holds Godot node instance id's. You can Query for these and get::<T: Node>() the node in your systems, e.g:

fn set_positions(mut erased_gds: Query<&mut ErasedGd>) {
    for mut node in erased_gds.iter_mut() {
        if let Some(node2D) = node.try_get::<Node2D>() {
            sprite.set_position(Vector2::ZERO)
        }
    }
}

Schedule systems for the _process or _physics_process frames

Use as_visual_system() and as_physics_system() to schedule your systems to run on the desired Godot frame, e.g:

app.add_system(set_positions.as_physics_system())

Preload godot PackedScene resources in bevy loading states, and spawn scenes as ErasedGd components

Godot scenes (.tscn files) can be "preloaded" (loaded in a dedicated Bevy loading State) in an AssetCollection with the use of bevy_asset_loader.

The scenes can then be queued for "spawning" (instantiate the PackedScene resource and add it to the Scene Tree) with the use of the GodotScene, e.g:

fn spawn_sprite(mut commands: Commands, assets: Res<MyAssets>) {
    commands.spawn(GodotScene::from_handle(&assets.sprite));
}

Checkout the examples folder for more.

bevy_godot4's People

Contributors

jrockett6 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.