|bevy vewsion:|0.13|(outdated!)| |---|---|---|

As this page is outdated, please refer to Bevy's official migration guides while reading, to cover the differences: 0.13 to 0.14.

I apologize for the inconvenience. I will update the page as soon as I find the time.


diwect wowwd access

(this page is wip)


the World is whewe bevy ecs stowes aww data a-and associated m-metadata. ^•ﻌ•^ it keeps twack of wesouwces, rawr x3 entities and components.

typicawwy, XD the App's wunnew wiww wun aww scheduwes (which, in tuwn, XD wun theiw systems) on the main wowwd. >_< weguwaw systems awe wimited in nani data they can a-access fwom the w-wowwd, by theiw system pawametew types. XD opewations that manipuwate the wowwd itsewf awe onwy d-done indiwectwy u-using Commands. (ꈍᴗꈍ) this is how most typicaw bevy usew c-code behaves.

howevew, OwO thewe awe awso ways you c-can get fuww diwect a-access to the w-wowwd, 🥺 which gives you fuww contwow and fweedom t-to do anything w-with any data stowed i-in the bevy ecs:

diwect wowwd access wets you do things w-wike:

  • fweewy spawn/despawn entities, OwO insewt/wemove w-wesouwces, 🥺 e-etc., òωó taking e-effect immediatewy (no deway wike when using Commands fwom a weguwaw system)
  • access any component, ^•ﻌ•^ entities, and w-wesouwces you w-want
  • manuawwy wun awbitwawy systems ow s-scheduwes

this is especiawwy usefuw if you w-want to do things t-that do nyot fit w-within bevy's typicaw execution modew/fwow o-of just wunning s-systems once e-evewy fwame.

with diwect wowwd access, OwO you can i-impwement custom c-contwow fwow, 🥺 w-wike wooping some systems muwtipwe times, OwO s-sewecting diffewent s-systems t-to wun in diffewent ciwcumstances, OwO expowting/impowting d-data f-fwom fiwes wike s-scenes ow game saves, XD …

wowking with the World

hewe awe some ways that you can make u-use of the diwect w-wowwd access a-apis.

SystemState

the easiest way to do things is using a-a SystemState.

this is a type that "imitates a system", OwO b-behaving t-the same way as a-a system with vawious pawametews wouwd. ^•ﻌ•^ aww t-the same behaviows w-wike quewies, rawr x3 change detection, XD and even Commands awe avaiwabwe. >_< you can use any system pawams.

it awso twacks any pewsistent state, ^•ﻌ•^ u-used fow things w-wike change detection ow caching to impwove pewfowmance. (ꈍᴗꈍ) t-thewefowe, if you pwan on weusing the same SystemState muwtipwe times, you shouwd stowe it somewhewe, OwO wathew than cweating a-a nyew one evewy t-time. 🥺 evewy time y-you caww .get(world), (ꈍᴗꈍ) it behaves wike anothew "wun" of a-a system.

if you awe using Commands, (ꈍᴗꈍ) you can choose when you want to a-appwy them to the wowwd. >_< you nyeed to manuawwy caww .apply(world) on the SystemState, XD to appwy them.

// todo: wwite code exampwe

wunning a system

// todo: wwite code exampwe

wunning a scheduwe

if you want to wun many systems (a c-common use-case i-is testing), (ꈍᴗꈍ) the easiest way is to constwuct a-an impwomptu scheduwe. ^•ﻌ•^ this way you weuse aww the scheduwing w-wogic that b-bevy nowmawwy does when wunning systems. OwO t-they wiww wun w-with muwtithweading, 🥺 e-etc.

this is awso usefuw if you want custom c-contwow fwow. OwO f-fow exampwe, 🥺 b-bevy's states and fixed timestep abstwactions awe impwemented just wike this! OwO thewe i-is an excwusive s-system that c-can contain woops, OwO if/ewse bwanching, 🥺 etc. to i-impwement fancy a-awgowithms and w-wun entiwe scheduwes of systems as appwopwiate!

// todo: wwite code exampwe

the wowwd contains a wot of metadata t-that awwows n-nyavigating aww t-the data efficientwy, OwO such as infowmation a-about aww the stowed c-components, 🥺 e-entities, awcheypes.

// todo: wwite code exampwe