Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic with headless build #505

Open
glklimmer opened this issue Sep 2, 2024 · 1 comment
Open

Panic with headless build #505

glklimmer opened this issue Sep 2, 2024 · 1 comment

Comments

@glklimmer
Copy link

Description:

Bevy provides a MinimalPlugins plugin bundle for headless bevy applications. Headless applications can be used to implement a game server for example. When trying to add the default Avian PhysicsPlugins Plugin Bundle Bevy a panics.

Minimal Example:

Here is a minimal example for a simple headless bevy application.

use avian3d::prelude::*;
use bevy::{app::ScheduleRunnerPlugin, prelude::*};
fn main() {
    App::new()
        .add_plugins(MinimalPlugins.set(ScheduleRunnerPlugin::run_once()))
        .add_systems(Update, hello_world_system)
        .add_plugins(PhysicsPlugins::default())
        .run();
}

fn hello_world_system() {
    println!("hello world");
}

Which results in the following error.

Resource requested by avian3d::collision::collider::backend::init_collider_constructor_hie
rarchies does not exist: bevy_asset::assets::Assets<bevy_render::mesh::mesh::Mesh>
Encountered a panic in system `hello world
avian3d::collision::collider::backend::init_collider_constructors`!
Encountered a panic in system `avian3d::collision::collider::backend::init_collider_constr
uctor_hierarchies`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!

Is this a bug?

Does PhysicsPlugins::default() include plugins that can not be used without bevy_window::WindowPlugin maybe? If yes, would it make sense to also provide a MinimalPlugins bundle for avian physics? What plugins would I need to exclude?

Thanks!

@datael
Copy link
Contributor

datael commented Sep 7, 2024

The panics do not seem to be related to WindowPlugin.

Info for you and anyone else who lands here trying to do the same in the future:

There's a few things missing when launching with MinimalPlugins that cause a panic:

  • AssetPlugin
  • ScenePlugin
  • Assets<Mesh> resource

Also missing but doesn't cause a panic:

  • TransformPlugin

These requirements are implicitly codified in tests.rs::create_app here, but this information isn't easy to find.

With the following changes I was able to get your code above running:

  fn main() {
      App::new()
          .add_plugins(MinimalPlugins.set(ScheduleRunnerPlugin::run_once()))
+         .add_plugins((
+             TransformPlugin,
+             bevy::asset::AssetPlugin::default(),
+             bevy::scene::ScenePlugin,
+         ))
+         .init_resource::<Assets<Mesh>>()
          .add_systems(Update, hello_world_system)
          .add_plugins(PhysicsPlugins::default())
          .run();
  }

If you don't need mesh colliders, you can avoid the need for Assets<Mesh> resource and ScenePlugin if you disable the bevy_scene and collider-from-mesh features.

I don't see a way that it could be possible to remove the reliance on TransformPlugin since so much of Avian works with GlobalTransform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants