# How to setup Modules

[Modules](https://maraudical.gitbook.io/status-effect-framework/type-specifics/scriptable-objects/module) have the biggest difference between default Object based Unity and ECS. Instead of hosting the logic inside of the [Module](https://maraudical.gitbook.io/status-effect-framework/type-specifics/scriptable-objects/module) itself it is instead handled by a user implemented system. To setup [Modules](https://maraudical.gitbook.io/status-effect-framework/type-specifics/scriptable-objects/module) for Entities you must inherit from IEntityModule. Here is an example from the samples provided.

{% code overflow="wrap" fullWidth="true" %}

```csharp
    public class DamageOverTimeModule : Module, IEntityModule
    {
        public void ModifyCommandBuffer(ref EntityCommandBuffer commandBuffer, in Entity entity, ModuleInstance moduleInstance)
        {
            DamageOverTimeInstance damageOverTimeInstance = moduleInstance as DamageOverTimeInstance;

            commandBuffer.AddComponent(entity, new DamageOverTimeEntityModule()
            {
                InvervalSeconds = damageOverTimeInstance.IntervalSeconds
            });
        }
    {
    
    public struct DamageOverTimeEntityModule : IComponentData
    {
        public float InvervalSeconds;
        public float CurrentSeconds; // For use in the ISystem
    }
```

{% endcode %}

When a new Status Effect is added to an Entity, it will add a burstable instance of any [Modules](https://maraudical.gitbook.io/status-effect-framework/type-specifics/scriptable-objects/module) as children of that Entity. There are many useful variables stored in the [Module](https://maraudical.gitbook.io/status-effect-framework/type-specifics/scriptable-objects/module), and they can be used like this:

{% code overflow="wrap" fullWidth="true" %}

```csharp
partial struct DamageOverTimeJob : IJobEntity
{
    public EntityCommandBuffer.ParallelWriter CommandBuffer;
    [ReadOnly]
    public ComponentLookup<ExamplePlayer> PlayerLookup;
    public float TimeDelta;

    public void Execute([ChunkIndexInQuery] int sortKey, ref DamageOverTimeEntityModule damageOverTime, in Module module)
    {
        Entity entity = module.Parent;
        
        if (PlayerLookup.TryGetComponent(entity, out ExamplePlayer player))
        {
            damageOverTime.CurrentSeconds -= TimeDelta;
            while (damageOverTime.CurrentSeconds <= 0)
            {
                damageOverTime.CurrentSeconds += damageOverTime.InvervalSeconds;
                player.Health -= module.BaseValue * module.Stacks;
                CommandBuffer.SetComponent(sortKey, entity, player);
            }
        }
    }
}
```

{% endcode %}

Note how in addition to querying for the custom DamageOverTimeEntityModule you can also get the base Module. The base Module has the following properties:

<table data-full-width="true"><thead><tr><th width="250">Name</th><th width="250">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>Parent</code></td><td>Entity</td><td>The parent Entity reference.</td></tr><tr><td><code>BaseValue</code></td><td>float</td><td>Base value of the <a href="../../type-specifics/scriptable-objects/statuseffectdata">StatusEffectData</a>.</td></tr><tr><td><code>Stacks</code></td><td>int</td><td>The current stack count.</td></tr><tr><td><code>PreviousStacks</code></td><td>int</td><td>The previous stack count.</td></tr><tr><td><code>IsBeingUpdated</code></td><td>bool</td><td>Whether the stack count was updated this frame.</td></tr><tr><td><code>IsBeingDestroyed</code></td><td>bool</td><td>Whether the <a href="../../type-specifics/classes/statuseffect">StatusEffect</a> was destroyed this frame.</td></tr></tbody></table>

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.
