rustbevy

How to use Windowdescriptor in Bevy?


use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .insert_resource(WindowDescriptor{
            width: 140.0,
            height:140.0,
            title: "Game of Life".to_string(),
            ..Default::default()
        })
        .run();
}

I don't know why this isn't working and its showing the following compile-error

error[E0277]: the trait bound `bevy::prelude::WindowDescriptor: Resource` is not satisfied                                                                                             
   --> src\main.rs:7:26
    |
7   |           .insert_resource(WindowDescriptor{
    |  __________---------------_^
    | |          |
    | |          required by a bound introduced by this call
8   | |             width: 140.0,
9   | |             height:140.0,
10  | |             title: "Game of Life".to_string(),
11  | |             ..Default::default()
12  | |         })
    | |_________^ the trait `Resource` is not implemented for `bevy::prelude::WindowDescriptor`

I was following this video and it works just fine in the video

I am learning how to use bevy game engine but when i pass windowdesciptor as an argument to the add_resource function and it shows me error


Solution

  • Since bevy 0.9

    The WindowDescriptor settings have been moved from a resource to WindowPlugin::window

    So your code should be:

    use bevy::prelude::*;
    
    fn main() {
      App::new()
        .add_plugins(DefaultPlugins.set(WindowPlugin {
          window: WindowDescriptor { 
            width: 140.0,
            height:140.0,
            title: "Game of Life".to_string(),
            ..default()
          },
          ..default()
        }))
        .run();
    }