The Entity Class
What is an Entity?
An entity is a gameplay class designed to use Components to give it functionality. By default an Entity only is created as an object in the engine, and can be added to the scene as a derivative of SceneObject.
This lets Entities have a transform in the level.
Beyond that, an Entity does little on it's own other than facilitating functionality calls to any Components it has added to it.
How does it work?
First, you need to create an Entity. This is done as any other object in Torque is made:
Once you've created it, it functions similarly to any other SceneObject. You can set it's transform, affecting it's position and rotation, add it to SimGroups, etc.
However, if you've created an Entity, you'll note that it doesn't look like anything. Selecting an Entity in the editor shows a simple 1x1x1 bounding box and nothing else.
This is where the magic of the Entity-Component system begins.
To get a Entity to do anything, you must add Components to it. Each Component defines the sort of behavior it will cause it's owner Entity to exhibit.
For example, lets add a Component so we can see the Entity - the RenderShapeComponent.
You need to create a basic template so there's an object to reference in script:
From there, you would create an instance of that template, which we'll then attach to the entity, like so:
If your model is valid, you'll note that the Entity now renders it.
All Components operate this way. Components can render, do collisions, physics, or any kind of gameplay functionality.
The entity merely acts as a intelligent container to let the Components do their function.