pub struct SyncWorldPlugin<L>(/* private fields */)
where
L: AppLabel;Expand description
A plugin that synchronizes entities with SyncToSubWorld between the main world and the sub world.
All entities with the SyncToSubWorld component are kept in sync. It
is automatically added as a required component by ExtractComponentPlugin
and SyncComponentPlugin, so it doesn’t need to be added manually when
spawning or as a required component when either of these plugins are used.
§Implementation
SyncWorldPlugin is the first thing that runs every frame and it maintains an entity-to-entity mapping
between the main world and the sub world.
It does so by spawning and despawning entities in the sub world, to match spawned and despawned entities in the main world.
The link between synced entities is maintained by the SubEntity and MainEntity components.
The SubEntity contains the corresponding sub world entity of a main world entity, while MainEntity contains
the corresponding main world entity of a sub world entity.
For convenience, QueryData implementations are provided for both components:
adding MainEntity to a query (without a &) will return the corresponding main world Entity,
and adding SubEntity will return the corresponding sub world Entity.
If you have access to the component itself, the underlying entities can be accessed by calling .id().
Synchronization is necessary preparation for extraction (ExtractSchedule), which copies over component data from the main
to the sub world for these entities.
|--------------------------------------------------------------------|
| | | Main world update |
| sync | extract |---------------------------------------------------|
| | | Sub world update |
|--------------------------------------------------------------------|An example for synchronized main entities 1v1 and 18v1
|---------------------------Main World------------------------------|
| Entity | Component |
|-------------------------------------------------------------------|
| ID: 1v1 | PointLight | SubEntity(ID: 3V1) | SyncToSubWorld |
| ID: 18v1 | PointLight | SubEntity(ID: 5V1) | SyncToSubWorld |
|-------------------------------------------------------------------|
|----------Sub world-----------|
| Entity | Component |
|---------------------------------|
| ID: 3v1 | MainEntity(ID: 1V1) |
| ID: 5v1 | MainEntity(ID: 18V1) |
|---------------------------------|
Note that this effectively establishes a link between the main world entity and the sub world entity.
Not every entity needs to be synchronized, however; only entities with the SyncToSubWorld component are synced.
Adding SyncToSubWorld to a main world component will establish such a link.
Once a synchronized main entity is despawned, its corresponding sub entity will be automatically
despawned in the next sync.
The sync step does not copy any of component data between worlds, since its often not necessary to transfer over all
the components of a main world entity.
A sub world may care about a Position component, but may not care about a Velocity component.
The extraction happens in its own step, independently from, and after synchronization.
Moreover, SyncWorldPlugin only synchronizes entities. Assets like meshes and textures are handled
differently.
Trait Implementations§
Source§impl<L> Default for SyncWorldPlugin<L>
impl<L> Default for SyncWorldPlugin<L>
Source§fn default() -> SyncWorldPlugin<L>
fn default() -> SyncWorldPlugin<L>
Source§impl<L> Plugin for SyncWorldPlugin<L>
impl<L> Plugin for SyncWorldPlugin<L>
Source§fn ready(&self, _app: &App) -> bool
fn ready(&self, _app: &App) -> bool
finish should be called.Source§fn finish(&self, _app: &mut App)
fn finish(&self, _app: &mut App)
App, once all plugins registered are ready. This can
be useful for plugins that depends on another plugin asynchronous setup, like the renderer.Source§fn cleanup(&self, _app: &mut App)
fn cleanup(&self, _app: &mut App)
Auto Trait Implementations§
impl<L> Freeze for SyncWorldPlugin<L>
impl<L> RefUnwindSafe for SyncWorldPlugin<L>where
L: RefUnwindSafe,
impl<L> Send for SyncWorldPlugin<L>
impl<L> Sync for SyncWorldPlugin<L>
impl<L> Unpin for SyncWorldPlugin<L>where
L: Unpin,
impl<L> UnsafeUnpin for SyncWorldPlugin<L>
impl<L> UnwindSafe for SyncWorldPlugin<L>where
L: UnwindSafe,
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more