Entity Creation - NocturnalWisp/Tynted-Engine GitHub Wiki

Getting Started

There are three main ways to create an entity:

  • Create from scratch without any components.
  • Create from a template within the engine.
  • Clone a previously created entity.

Both are valid choices, but if you want full control I suggest creating an entity from cratch.

Scratch

You need to access the ECSEngine, and create a new entity by it's name, and possibly a tag or a scene. This function returns an entityID which you often do not need to worry about, unless you are trying to optimize excessively.

ECSManager.CreateEntity(entityName, tag(optional), sceneName(optional));

Now that you have created the entity, you can add, remove, or set components on that entity.

Template

For template entities, you do not use the ECSEngine static class, instead you use the Entity class which contains multiple functions to create template entities. These functions actually access the ECSEngine class and call CreateEntity for you, they also add certain components depending on the template type. This is for fast creation of entities.

//With no components. (The same as calling ECSManager.CreateEntity)
Entity.CreateEmpty(name, tag(optional), scene(optional));

//With a transform component.
Entity.CreateTransform(name, tag(optional), scene(optional));

//As a sprite (SpriteRenderee, Transform)
Entity.CreateSprite(name, texture, tag(optional), scene(optional));

Cloning

Cloning is used when you want to create an entity that has all of the same components and attributes as another entity. This is why if you are creating a new component, you always need to have a Clone function, this is utilized to create a new component of that type for use when cloning an entity. It's actually fairly simple to clone an object with this in mind:

//Clones with completely with no changes other than adding "(Clone)" to the end of the name.
Entity.Clone(entityIDToClone);

//Allows you to set the name, tag, and scene of the newly cloned entity.
Entity.Clone(entityNameToClone, newEntityName, newEntityTag, newEntitySceneName);

Conclusion

You should know how to create entities in many different ways now. I hope this small doc will help you with speeding up iteration of your game!