How to setup Modules
Modules have the biggest difference between default Object based Unity and ECS. Instead of hosting the logic inside of the Module itself it is instead handled by a user implemented system. To setup Modules for Entities you must inherit from IEntityModule. Here is an example from the samples provided.
When a new Status Effect is added to an Entity, it will add a burstable instance of any Modules as children of that Entity. There are many useful variables stored in the Module, and they can be used like this:
Note how in addition to querying for the custom DamageOverTimeEntityModule you can also get the base Module. The base Module has the following properties:
Parent
Entity
The parent Entity reference.
Stacks
int
The current stack count.
PreviousStacks
int
The previous stack count.
IsBeingUpdated
bool
Whether the stack count was updated this frame.
Instead of querying the Module every frame, you could also include the ModuleUpdateTag or the ModuleDestroyTag in the query to only execute when those components are enabled. You could also just query for the ModuleUpdateTag and check the IsBeingDestroyed bool. This can lead to more performant Module systems.
Last updated