Skip to content

Where to insert a Resource needed for a Plugin when expansive computation is required? #2519

Answered by will-hart
IceSentry asked this question in Q&A
Discussion options

You must be logged in to vote

I'm not sure what the "official" approach is, but I would add the resource in an "empty" state in the build function. I would then have the expensive setup process work in a separate, earlier game state to the system(s) that consume it. Depending on the expensiveness of your expensive things you may also want to consider running the expensive things using bevy's async features.

For example a sync version might look something like this:

// in plugin builder
app.insert_resource(ExpensiveComputationForThis::default())
    .add_system_set(SystemSet::on_enter(MyGameState::DoExpensiveThings).with_system(do_expensive_things.system())
    .add_system_set(SystemSet::on_update(MyGameState:AfterDoin…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@IceSentry
Comment options

IceSentry Jul 22, 2021
Collaborator Author

@will-hart
Comment options

Answer selected by IceSentry
Comment options

You must be logged in to vote
2 replies
@IceSentry
Comment options

IceSentry Jul 24, 2021
Collaborator Author

@ManevilleF
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants