#Using the result of a one-off async task

2 messages · Page 1 of 1 (latest)

hexed crescent
#

So I cobbled together a system that waits for the game map to generate in a background task but I have some doubts.

  1. What used to be a startup system now keeps running but effectively only runs once. Can I express this better?
  2. It just looks kinda funky

This is how the start of the system goes where I'm wrangling the Task.

    if generate_map_task.is_empty() {
        return;
    }
    let (task_entity, mut task) = generate_map_task.single_mut();
    let mapprototype = match future::block_on(future::poll_once(&mut task.0)) {
        Some(Ok(result)) => {
            commands.entity(task_entity).despawn();
            result
        }
        Some(Err(e)) => {
            error!("something went wrong: {}", e);
            commands.entity(task_entity).despawn();
            return;
        }
        None => return,
    };

Full context: https://github.com/keis/explore-game/commit/8f1bc48a6996371629299b1d202bdf189b47f518

delicate cargo
#

This is almost line for line what I have done in https://playspacefarer.com?mtm_campaign=bevy_help , async tasks are always gonna be messy. Also 'startup systems' that run continuously are fine as long as you're not doing anything too resource intensive. If it really bothers you, you can use run conditions to prevent it from running later.

Spacefarer

In Spacefarer, you wake up to find yourself lost in an infinite, procedurally generated universe. Repair your ship and take to the stars.