Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bevy_quill_obsidian will crash if you use StateScoped to remove UI when state changes #3

Open
PhaestusFox opened this issue Jul 19, 2024 · 6 comments

Comments

@PhaestusFox
Copy link

I was trying to use StateScoped to despawn my UI when the state change but this results in a crash because bevy_quill_obsidian tries to access the entity for a hover check after it has respawned, what is the correct why to remove UI? I don't think the application should crash if I despawn part of the UI

@viridia
Copy link
Owner

viridia commented Jul 19, 2024

So the current solution for despawning UI roots is less than ideal, as it requires calling .raze() on the view root.

The eventual goal is to use relations to track ownership, along with component hooks, so that whenever you delete a view root entity all of the things that it owns also despawn automatically. But this is of course waiting on relations...although it may be possible to do something with just component hooks alone. It's a bit complex because hooks only get a deferred world, which means that any actual despawning has to be handled in the command queue. Researching this is one of the things on my TODO list.

@PhaestusFox
Copy link
Author

how exactly do I call raze on a view root? I have been trying to work it out but cant work out how to get access to a pubic call to raze, the only one I found doesn't relate back to my root node in any way, I am probably missing something obvious.

p.s. would it be possible to add an example of how to cleanup or remove UI

@viridia
Copy link
Owner

viridia commented Jul 20, 2024

OK, I added some public APIs for despawning a view root, and an example that illustrates how it works: b169936

The code isn't pretty, but as I mentioned earlier, hopefully this will get better.

@viridia
Copy link
Owner

viridia commented Jul 22, 2024

I've worked on this more. You should now be able to despawn view roots normally with despawn(). In order to make this work, I had to change the raze() method to take a DeferredWorld instead of a World, which meant changes to every view impl. However this is generally good that razing no longer requires world access.

@dbidwell94
Copy link

Ah, I thought I was going crazy. So this lib is the reason my StateScoped menus are crashing when switching to a new SubState. This lib is great so far! I just really wish that StateScoped UI would work as well :/

@dbidwell94
Copy link

A little helper function I'm using for now. But long term: I would love to be able to use StateScoped again!

pub fn despawn_ui_with_marker<C: Component>(mut commands: Commands, query: Query<Entity, With<C>>) {
    commands.entity(query.single()).despawn();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants