#Accessing App Resources Outside of Systems?

14 messages · Page 1 of 1 (latest)

pulsar tiger
#

I want to be able to access application resources in regular old functions. Is there a way to do this?

#

Basically, a way to access them without adding them as a system to the App::new() function.

burnt summit
#

you mean by having still access to the app? like app.world.resource::<T>()?

pulsar tiger
burnt summit
#

that should work then, right?

pulsar tiger
burnt summit
#

app.world.resource::<type of the resource>()
and the mut version
app.world.resource_mut::<type of the resource>()
These fetch the resource having an app instance.

pulsar tiger
#
use bevy::prelude::*;

/* Code for MyResource */

fn main() {
  App::new()
    .insert_resource(MyResource::new())
    /* New App Code */
    .run();
}

fn some_random_function_not_added_as_a_system() {
  /* Code for accessing MyResource from App!? How to do that... */
}
#

@burnt summit

#

Can you fill in the gaps for me?

#

I really need a full-ish example to help.

#

Like, not an entire game, just like a simple 15 line main.rs file.

#

Something simple, but complete.