diff --git a/src/projectile_pool.cpp b/src/projectile_pool.cpp index 170f404..b18c219 100644 --- a/src/projectile_pool.cpp +++ b/src/projectile_pool.cpp @@ -31,15 +31,19 @@ void ProjectilePool::set_data(Ref data) { } Node3D *ProjectilePool::claim_projectile() { + Node3D *node{this->inactive[0]}; + this->add_child(node); + this->inactive.erase(node); + this->active.push_back(node); if(inactive.is_empty()) { size_t const new_count = this->count + this->data->get_projectile_count() * this->data->get_rounds_per_second() * 2; for(size_t i{this->count}; i < new_count; ++i) this->inactive.push_back(this->instantiate_new()); + this->count = new_count; } - Node3D *const ret{this->inactive[0]}; - this->inactive.remove_at(0); - this->active.push_back(ret); - return ret; + if(node == nullptr) + UtilityFunctions::push_error("Failed to spawn node"); + return node; } void ProjectilePool::return_projectile(Node3D *node) {