bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.3k stars 3.48k forks source link

Add `world` and `world_mut` methods to `WorldChildBuilder` #15414

Open benfrankel opened 2 hours ago

benfrankel commented 2 hours ago

What problem does this solve or what need does it fill?

Allow World access when you only have a WorldChildBuilder.

What solution would you like?

Add world and world_mut methods to WorldChildBuilder, returning references to the inner &mut World. This doesn't have to be unsafe like EntityWorldMut::world_mut, because the latter is only unsafe due to the EntityLocation stored in EntityWorldMut that could become invalidated. There is no EntityLocation stored in WorldChildBuilder.

What alternative(s) have you considered?

None.

benfrankel commented 2 hours ago

It may be nice to add ChildBuilder::commands as well. Currently there's only a queue_command method there, which is insufficient if you want to access e.g. an extension trait or method on Commands.

viridia commented 2 hours ago

Just FYI, My main reason for wanting this is to add extension traits on WorldChildBuilder.