summaryrefslogtreecommitdiff
path: root/ecs/src/actions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/actions.rs')
-rw-r--r--ecs/src/actions.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs
index 2dd68bf..ba3ced5 100644
--- a/ecs/src/actions.rs
+++ b/ecs/src/actions.rs
@@ -16,11 +16,18 @@ pub struct Actions<'world>
impl<'world> Actions<'world>
{
- /// Queues up a entity to spawn at the end of the current tick.
- pub fn spawn<Comps: ComponentSequence>(&mut self, components: Comps)
+ /// Queues up a entity to spawn at the end of the current tick, returning the [`Uid`]
+ /// that the entity will have.
+ pub fn spawn<Comps: ComponentSequence>(&mut self, components: Comps) -> Uid
{
- self.action_queue
- .push(Action::Spawn(components.into_parts_array().into()));
+ let new_entity_uid = Uid::new_unique(UidKind::Entity);
+
+ self.action_queue.push(Action::Spawn(
+ new_entity_uid,
+ components.into_parts_array().into(),
+ ));
+
+ new_entity_uid
}
/// Queues up despawning a entity at the end of the current tick.
@@ -149,7 +156,7 @@ impl Ref<'_>
#[derive(Debug)]
pub(crate) enum Action
{
- Spawn(Vec<ComponentParts>),
+ Spawn(Uid, Vec<ComponentParts>),
Despawn(Uid),
AddComponents(Uid, Vec<ComponentParts>),
RemoveComponents(Uid, Vec<Uid>),