Entity-Component Model

Overview

Entity is the base class for objects that are managed by the high-level engine.

To improve flexibility, entity are component-based: they can contains as many components as required, containing data and/or logic.

media/7438980.png

A @'Xenko.Engine.Entitycomponent' is tied to its entity (that is, one component can't be added to two entities at the same time).

How to create an entity and some components

  1. // Create entity
  2. var myEntity = new Entity();
  3. // Create a model component (so that model is rendered)
  4. var modelComponent = new ModelComponent { Model = model };
  5. myEntity.Set(ModelComponent.Key, modelComponent);
  6. // Set entity position
  7. myEntity.Transformation.Translation = new Vector3(100.0f, 100.0f, 0.0f);
  8. // Add entity to scene; from now on its model will be rendered
  9. Entities.Add(myEntity);