-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add entity template #114
Comments
Thats exactly what i just wanted to task... in unity those are called archetypes. And its actually pretty usefull. Are there any plans yet ? |
This is different from unity's archetypes. Archetypes store all their component data next to each other, meaning that when you add or remove a component you need to move all the other components data to the new archetype of the entity. DefaultEcs currently use arrays of components to store the data. That means when you access multiple components on an entity you will jump around in memory which is slower than archetype (while having predictable memory access to help the cpu cache) but adding/removing a component only makes a change on this specific component array (simpler and faster). What I meant by template here is to literally have an entity template, a special kind of entity which is not picked up by the queries but on which you can set components and later use to create real entities with the same composition to simplify some use case (like having an entity factory to create particle entities). I am not sure there is a real benefit yet, you could just as easily have a method to create your entity with all your needed components but I have seen it in other frameworks so why not. The other good point is that this template could be serialized so this "factory" becomes data editable outside of the game instead of being hard coded. As for real archetype, I don't see myself adding it in short or mid term, it is quite hard to do properly in pure c# because of memory management and the need to create archetype types on the fly. But the idea is still here :) I just want to keep things simple for now. |
Alright thanks for the insight into default.ecs ! :D Such entity factores/cloneable entities would come in pretty handy and could save some time, so i actually think its a very good plan ! Besides that, more performance is always better ^^ but i can fully understand if "real" archetypes will not become a feature, the amount of work must be insane. Furthermore default.ecs IS already the fastest or the second fastest ( looking at LiteECS ) c# ecs out there. I ran a little movement simulation yesterday on my server and was able to process up to 8 million entities with constant 60 FPS ( ParallelRunner 4, only structs, usage of references )... this is just insane im not even sure if more is even possible :D Keep up the great work ! |
I found that the "CopyTo" method of Entity class has pretty much implemented the functionality of entity templates. We can create an entity, disable it, set its components on demand, and use it as a template. When there's need to create an entity from the template, just copy from this "template entity" and all is done. The only weakness is that it can't specify whether a component is copied from the template or referenced from the template. |
yep as you said I am also using |
Useful to quickly create entities with the same composition
Should add a way to state if created entity from the template should share component or not
The text was updated successfully, but these errors were encountered: