0

I'm building a city building game prototype where i have villagers doing many different tasks at the same time, such as carrying stuff, building, harvesting, for that purpose i created a TaskManager singleton script with a task backlog array and an active tasks array, that can select which tasks go from backlog to active based on priority, run the respective run_task() method of each task on the active list and remove them when their done. I'm still learning rust and bevy, but from what i read, i can't really make a singleton in bevy as i do in godot. What are my options in this case? Sorry if this is not the place for this type of question but I'm having a hard time finding information about this type of thing related to the engine and rust.

Onizudo
  • 313
  • 3
  • 7
  • 21

1 Answers1

1

Unless I'm misunderstanding what you need, this is done by using a "resource". From the Bevy book:

... But most Apps will also require "globally unique" data of some kind. In Bevy ECS, we represent globally unique data using Resources.

Used like:

App::build()
    .add_resource(TaskManager{ ... })
    .add_system(process_tasks.system())
    ...
fn process_tasks(manager: Res<TaskManager>, ...) {
    ...
}
kmdreko
  • 42,554
  • 6
  • 57
  • 106