You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use OnExit and OnEnter to switch between UI pages. During OnExit I use commands to despawn entities recursively from the root node and then OnEnter to generate new content. My issue is with entities that have UiImage components despawned via commands and new entities with their UiImage handle set via a custom command that refer to the same image. I assume all asset types would have the same issue though.
What went wrong
I am using images for UI icons and if an icon that was used in the despawned page is fetched from with AssetServer.load(path) I can't see the icon rendered. This happens even if I add an apply_deferred before spawning the new page content.
Additional information
There doesn't seem to be an issue with loading the image if I depsawn the entity ahead of the switch of the pages. I assume it works because the frame ends with the asset cleaned up and then the loads it again correctly in a later frame.
Here is the command I use to set images:
structSetImage{path:String,}implEntityCommandforSetImage{fnapply(self,entity:Entity,world:&mutWorld){let handle = ifself.path == ""{Handle::default()}else{
world.resource::<AssetServer>().load(self.path)};letmut q_ui_image = world.query::<&mutUiImage>();letOk(mut image) = q_ui_image.get_mut(world, entity)else{warn!("Failed to set image on entity {:?}: No UiImage component found!",
entity
);return;};if image.texture != handle {
image.texture = handle;}}}
The text was updated successfully, but these errors were encountered:
I think I just ran into this same issue, for the same reasons listed. I likewise use OnExit(SomeState) to despawn entities that are re-spawned in the next state, OnEnter(OtherState). In my game, I observe that the textures fail to load (using TextureAtlasLayout in my case) but all of the normal entity logic behaves the same.
I've tried tinkering with apply_deferred before or after the state transitions (as well as splitting up my teardown despawner into a separate system, and using chain to pair them w/ auto apply_deferred in 0.13), but no luck.
As with the OP, the entities spawned/despawned refer to the same image path from the asset server.
Bevy version
0.13
What you did
I use
OnExit
andOnEnter
to switch between UI pages. DuringOnExit
I use commands to despawn entities recursively from the root node and thenOnEnter
to generate new content. My issue is with entities that haveUiImage
components despawned via commands and new entities with theirUiImage
handle set via a custom command that refer to the same image. I assume all asset types would have the same issue though.What went wrong
I am using images for UI icons and if an icon that was used in the despawned page is fetched from with
AssetServer.load(path)
I can't see the icon rendered. This happens even if I add anapply_deferred
before spawning the new page content.Additional information
There doesn't seem to be an issue with loading the image if I depsawn the entity ahead of the switch of the pages. I assume it works because the frame ends with the asset cleaned up and then the loads it again correctly in a later frame.
Here is the command I use to set images:
The text was updated successfully, but these errors were encountered: