Comments (3)
Hi! Thank you so much. I now successfully moved from plain queries to all-systems, which works beautifully, and even better: everything works as expected. I must say I love legion.
from legion.
My current way of removing missiles looks like this:
fn remove_dead_missiles(world: &mut World) {
let mut entity_list = vec![];
let mut query = <Entity>::query();
for entity in query.iter(world) {
entity_list.push(*entity);
}
let mut to_delete = vec![];
for e in entity_list {
let ent = world.entry(e).unwrap();
match ent.get_component::<Missile>() {
Ok(m) => if m.is_set_off {
to_delete.push(e);
},
Err(_) => (),
}
}
for del in to_delete.iter() {
world.remove(*del);
}
}
from legion.
Hi @nyvs, not sure about the idiomatic way, but I can share with you my approach for solving such tasks.
All my logic is packed into systems generated via #[legion::system]
macro (and executed in Schedule
), so when I need to add/remove entities or components I simply request my system to access CommandBuffer
and record corresponding commands into it.
In your case, such a system can look like this:
use legion::{Query, systems::CommandBuffer, world::SubWorld};
#[legion::system]
fn remove_exploded_missiles(objects: &mut Query<(Entity, &Missile)>,
commands: &mut CommandBuffer,
world: &mut SubWorld)
{
for (entity, missile) in objects.iter(world) {
if missile.is_set_off {
commands.remove(entity);
}
}
}
Please let us know if this does not work for you.
from legion.
Related Issues (20)
- Should maybe_changed always match at least once?
- Failed World::clone_from(), because of missing Duplicate::register_clone(), asserts
- Include license file in legion_codegen crate
- Make `KnownLength` public
- Using systems and scheduler in wasm? HOT 1
- How to apply Filter in #[system] with Query<(Entity, &Component)> HOT 3
- Resources are marked as !Send and !Sync? HOT 2
- Game map questions (Resource vs Entity) HOT 1
- how to remove/stop system? HOT 2
- How to get component/components from a particular entity? HOT 2
- Fallible systems
- Is there way to push entities with dynamic components?
- Query with ordering / sorting?
- Prototype game no longer working in browser after adding legion
- Delete entities based on component? HOT 2
- Is project dead? HOT 2
- Linking legion entities with rapier2d colliders.
- can't build at webassembly
- crossbeam-0.1.6 cannot transmute between types of different sizes, or dependently-sized types
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from legion.