Entity Components
Entities can have components, which are code classes that can be attached and detached from Entities via code during gameplay. Because Entity Components are open-ended, they can be used for almost anything from giving players power-ups, to handling advanced NPC AI behaviors. Entity Components are also networked, so they will be available on both the client and server once added to an Entity.
Many other game engines use a component model similar to this, including Unity and Unreal.
Defining Components
Components can also have Events.
Creating Components
You can create, get and remove components from an Entity at any time, in this example we simply assign them on Spawn.
Binding Components
If you need to frequently access a component and want a reference that is networked between server and client, you can set up the component as a property with the BindComponent
attribute.
Component will now refer to the same networked component on both client and server.
- Note that you still need to create the component, and you should do so only from the server.
- You also do not need to assign the component to the property, which should have no setter.
Footnotes
- Clients are also entities and can have components on Client.Components