Hi!

I’ve been learning Bevy and LOVING IT, there’s only one thing confusing me. Many components appear to be created magically even if not specified in the Bundle passed to commants.spawn.

For example, when I spawn just a Sprite component, the entity seems to automatically get a Transform component, even if I didn’t give it one.

Similarly, this example spawns a Screenshot component, which apparently results in a Capturing component that can be queried later.

Are these “implicit” components documented somewhere? I took a short look at the TransformPlugin for example but I can’t seem to figure out where these components come from.

Thanks y’all!

  • LuciferMorningWood@lemm.ee
    link
    fedilink
    arrow-up
    7
    ·
    edit-2
    10 days ago

    It’s a feature called required components. Basically, you can use #require(components list here) attribute to say that when a component is inserted, also insert required components. I don’t know if there’s a documentation for it, or specifically what component requires what, personally when I’m looking for required components I’m looking at component’s source and they’ll be listed there (Sprite, for example https://docs.rs/bevy_sprite/0.16.0/src/bevy_sprite/sprite.rs.html#20)

    Note that required components work recursively: when component requires a component that has it’s own requirements, they’ll also be inserted

    • TehPers@beehaw.org
      link
      fedilink
      English
      arrow-up
      2
      ·
      10 days ago

      The required components are documented in the component impl block. Scroll down in docs.rs until you find impl Component and they’ll show up there.

      Apparently there were issues getting required components to show up at the top of the page (from my understanding anyway), so for now they live there.

    • PotatoesFall@discuss.tchncs.deOP
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      10 days ago

      Ah, that’s it! Thank you so much.

      I was digging through the systems functions, totally forgot to just look at the attributes. Not that experienced with rust yet :P