diff --git a/libs/ecs/source/container.cpp b/libs/ecs/source/container.cpp index 30708fcf..6fe56039 100644 --- a/libs/ecs/source/container.cpp +++ b/libs/ecs/source/container.cpp @@ -30,20 +30,11 @@ namespace psemek::ecs handle container::clone(handle const & entity) { + if (auto result = try_clone(entity)) + return *result; + auto const data = entity_list_.get_entities()[entity.id]; - if (!data.table->non_copyable_components().empty()) - throw entity_not_cloneable(entity, data.table->non_copyable_components()); - - auto table = data.table; - if (table->get_iteration_data()) - table = table->get_delayed_table(); - - auto id = entity_list_.create(table, table->row_count()); - handle handle{id, entity_list_.get_entities()[id].epoch}; - - table->copy_row(handle, data.table, data.row); - - return handle; + throw entity_not_cloneable(entity, data.table->non_copyable_components()); } std::optional container::try_clone(handle const & entity)