Im looking into ECS on a project with heavy performance need - notably a lot of various physical objects in a block-based vehicle construction game.
What I currently have:
- a monobehaviour-based approach, witch construction cubes of various sizes and features (additional monobehaviours), and the same for weapons, also with various sub parts and monobehaviour components
Where I am with Dots:
- Following tutorial videos, I kind of got the basics of Entities workflows, with Authoring, Components and Systems, so I can define a single entity, and spawn it in (impressive) numbers in the subscene
What Im confused with:
- Its unclear to me how to work with traditional prefabs and entities. I understand I cant make a gameobject prefab with multiple parts and monobehaviours and expect it to work as an Entity, but on the other end I assume there are simpler ways to create Entities than just hard coding every component in a dedicated baker?
Planned approach:
As the blocks and weapons scripts are not performance intensive, Im only looking at ECS/Dots for physical simulation performance, as I have a lot of active blocks.
My idea was whenever I spawn a block or weapon in the world, I want to deactivate that gameobject and spawn just a basic doppelganger Entity of it with equivalent meshes and PhysicsColliders component.
When a player starts interacting with it (raycast hits the collider) I reactivate the actual gameobject version of it, move it to the Entity position and hide the doppelganger. Vice-versa when the player ends the interaction.
-
Is that “doppelganger” approach okay?
-
Do I need to write a specific set of authoring + components + spawner for each version of the blocks/weapons, or is there a way to factorize/automatize that, as it doesnt really matter what the original gameobject is, I just want an Entity made one or more MeshRenderers and Colliders?
-
Its apparently not possible to reference gameObjects or monobehaviour components form Entities Components, so I intend to manage a dictionary on a monobehaviour component to reference those, and only pass an int/string ID for the Entities to reference those. Would that be wrong?
-
How can I reference Entity components (such as PhysicsCollider) in an Entity? For instance, my weapon have colliders used as interaction zones. If I wanted to reference them in the Entity so that I can enable/disable them at a later point, how can I do that?
Thanks in advance