Last active
April 26, 2022 11:49
-
-
Save danielytics/dd2cd6601c85f3b210e4bc0541febf58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void mergeEntity (entt::registry& source_registry, entt::registry& destination_registry, entt::entity source_entity, entt::entity destination_entity, bool overwrite_components) | |
{ | |
for(auto [id, source_storage]: source_registry.storage()) { | |
auto destination_storage = destination_registry.storage(id); | |
if (destination_storage != nullptr && source_storage.contains(source_entity)) { | |
if (! destination_storage->contains(destination_entity)) { | |
destination_storage->emplace(destination_entity, source_storage.get(source_entity)); | |
// If destination already contains the component, then either skip or "overwrite" | |
} else if (overwrite_components) { | |
destination_storage->erase(destination_entity); | |
destination_storage->emplace(destination_entity, source_storage.get(source_entity)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment