ECS - Steelhead-Games/CharmQuarkEngine-wiki GitHub Wiki

How to create a new component

If you want to create a component that can be serialized, deserialized and added to the reflection system

  1. You have to create a class inherited from EntitySystem::EntityComponent. There are also predefined classes FloatComponent, Vector3FloatComponent and Vector4FloatComponent that already contain predefined Serialization methods. The EntitySystem::EntityComponent class contains the API for the engine to work with; this way, it can be connected to all the necessary systems.
  2. You have to register the component in the GameFramework::RegisterComponents() method. Like this
EntitySystem::EntityManager::RegisterComponent<Velocity>(m_World);
  1. For your component, define methods Serialize, Deserialize and RegisterComponent. An example of what you have to do about them you can find in the class ENTITY_SYSTEM_API Position final : public cqe::EntitySystem::Vector3FloatComponent class.

If you want to create a small component that will not leave the C++ gameplay code

Just use struct. That's it

struct Velocity
{
float x, y, z;
}

and then use it with the entities. Don't overcomplicate your code and don't do redundant work.

⚠️ **GitHub.com Fallback** ⚠️