I'm trying to tag certain entities for a function that should execute later in the same frame (in Update) since others that execute on that same frame depend on it.
I can't insert tags with Commands because .insert would only apply after Update.
What would you do in my place?
Should I just put their entity numbers into a vec? (could be hundreds of entities)
#Tagging Entities For Same Frame
24 messages · Page 1 of 1 (latest)
you could manually run apply_deferred right after that system, so that the component is added.
just make sure that all 3 systems ( apply_deferred and your other 2) are correctly ordered so that they run after each other.
or the other thing you could do is to just use events?
store the entity ID in the event and read the event in the other system as well as have a query in it. then get the entity out of the query
It's a bunch of entities so it'll have to be an event with a Vec<Entity> field
Which is possible
But I have too many events rn
I'll try the apply_deferred next time I get to that project
Thanks
you could also send out one event per entity, don't think it would be that big of a deal?
Oh right, haven't thought of that
I realized the reason I didn't do it in the first place (that's actually exactly what I'm doing with spawns, I just forgot cause I wrote it a few months back haha)
I'm actually marking the ones that should not despawn
which means I'll have to run over the query and for each event remove an answer from it or something, leaving me only with ones that weren't tagged as "not to despawn"
which means I'm probably better off with apply_deferred haha
I can't make the code compile
Well show the Code, maybe i can help
Thanks
It seems that functions that take &mut World can't take anything else
But if I run a function with &mut World after the function that determines which things should not despawn it does nothing
yeah a system that takes in a World is considered an exclusive system: https://bevy-cheatbook.github.io/programming/exclusive.html (some of it is a bit outdated, for 0.9 instead of 0.12)
you could use a paramset to take in more than just the world: https://bevy-cheatbook.github.io/programming/paramset.html
But if I run a function with &mut World after the function that determines which things should not despawn it does nothing
are you running applied deferred in between?
and also, what do you mean with "should not despawn"? what exactly are you even trying to achieve? understanding that would make me be able to help you better
currently I have the chained systems and right after the function that adds tags I call a system with only &mut World in which I only run apply_deferred
alright, I'll try to provide more details:
I'm making a game with lots of numbered tiles
There could be a case in which I generate a new board with 49000 tiles instead of 50000
I wouldn't want to despawn everything and then spawn everything, considering I'll be using the exact same 49000 tiles for the smaller board
so, when building the smaller board I mark each tile that I use in the new one as "DoNotDespawn", and then in the despawner I call a query with all the ones not tagged with it, so that it will despawn them (I still don't want those thousand tiles to exist in the game world, since they'll slow down each query)
so you're running apply_deferred in the world system?
how about you do something like this:
fn main() {
let mut app = App::new();
app
.add_systems(Update, (system_a, apply_deferred, system_b).chain())
.run();
}
that's what I'm doing right now
unless you mean apply_deferred literally as is and not a function that does apply_deferred on a world &mut
no i mean litteraly "apply_deferred", thats a system built into bevy that you can call whenever and that is being called by bevy itself after every schedule
Instructs the executor to call System::apply_deferred on the systems that have run but not applied their Deferred system parameters (like Commands) or other system buffers.
ok sounds great
I can't try it out right now (busy with university stuff) but I'll try when I get to it in a few hours
thanks