Entities and Components
Entities and Components are core to how developers will interface with the All Out Engine.
Tip
For users familiar with Unity:
- Entity is equivalent to GameObject
- Component is equivalent to MonoBehaviour
For users familiar with Unreal:
- Entity is equivalent to Actor
- Component is equivalent to Component (no one could have predicted this)
Entities
The Entity class represents the simplest form of something that can exist in a game. Entities are the base building block for constructing your All Out game, they act as a container for components.
Entity Usage
Creating
Entities can be created a few different ways:
- In editor Editor Usage
- Prefab instantiation Prefabs
- Manual creation in C# using Entity.Create
Destroying
Entities can be destroyed in C# using Entity.Destroy
Adding Functionality
Functionality is added to Entities through Components. You can add components at edit time to entities in the scene (See Editor Usage). You can also add them from C# using Entity.AddComponent
Programmatically Finding Scene Entities
When writing scripts you may want to reference an entity directly (to manipulate or retrieve its fields). There are a few ways to retrieve an entity:
- If you want to reference the Entity on which your component resides, every component has a
Entity
field (e.g.Entity.Position
in a component will get the "parent" entities position) - You can mark a component's field as Serialized in a component. This field can be set from the editor UI and will be available at runtime.
- Using one of the
Find
functions: FindByName, FindByNetworkId
Engine Components
There are many pre-defined components that come standard with All Out. They provide out of the box behavior that is useful for most games.
Creating
To create a component you start by create a C# class and inheriting from AO.Component. After saving your script All Out will automatically detect a new component type that you can now use in editor or your scripts.
using AO;
public class MyComponent : Component {}
Adding Behavior
Component has a variety of functions that you can override to start adding behavior. These will be familiar if you have experience with a popular engine like Unity
Awake
Called once immediately on component creation. Used for initializing itself, this means that during awake users should not reach out to other components on the same entity (they may not have had their awake called yet) or make any calls to the network.
Update
Called once every frame before the physics simulation has stepped. This is where the bulk of your gameplay logic will live.
LateUpdate
Called once every frame after the physics simulation has stepped.
OnDestroy
Called immediately when the component is removed from the entity or the entity is being destroyed.
Note: All Out does not have the "Start" lifecycle method.