Hi! Thanks for reading! To be brief, I would like to know if it's possible to get a component's entity without running a query. I want to implement a method on a component that when called, deletes it and its entity after some time. Is this possible? Also, is this something I should be doing at all? I'm not too familiar with ECS or the design patterns I should and shouldn't use for it. Any tips would be greatly appreciated!
#Is it possible to get the entity a component is attached to?
1 messages · Page 1 of 1 (latest)
I'm not sure what you mean by "not running a query" or why you would not want to, but you can just request the entity whenever you query for a component, e.g.
ship_query: Query<Entity, With<Ship>>
This gives the Entity the Ship component is attached to.
Hey, thanks for the reply! I would like to be able to call it without having to specify something along those lines in the system definition for brevity. Do components have an attribute with information about its entity, or something similar?
No they don't, they are literally just the struct/enum you wrote
The derive AFAIK doesn't really do anything presently, it's just future-proofing
It sounds like fighting the ECS
So It'd be better to pass the entity in through the system itself?
What actually triggers this delete?
a function call within a system
but what circumstance?
I want to make a crate that destroys itself when hit enough. I want to handle this through an event which would call the destroy method on the crate and destroy it.
That sounds like OOP I guess
How would you recommend I do it in ECS?
Just make a system that destroys all crates that have 0 hp or something
and by destroy there I mean despawn
Components in principle are just data, systems are the behaviour