Selective System Authoring

Systems with Multiple Implementations

In some cases, we can have an abstract system type with multiple implementations. For example:

  • Transports: we have one abstract TransportServer/ClientSystem class, but can have multiple implementations like kcp, and later Websockets/Steam/etc.

  • Interest Management: we have one abstract InterestManagementSystem, and an explicit BruteForceInterestManagementSystem. We might also have a grid system, room system, etc. later.

By default, ECS always creates all systems in the project.

This is a problem, because even if our project has 3 different interest management implementations, we only ever want to use one of them.

The Solution

The solution is to disable systems by default, and only enable them if an authoring component is added to the scene:

1. Add the [DisableAutoCreation] attribute to systems with multiple implementations:

using DOTSNET;

[ServerWorld]
[DisableAutoCreation]
public class BruteForceInterestManagementSystem : InterestManagementSystem
{
}

2. Create an Authoring component that implements our SelectiveSystemAuthoring interface:

using DOTSNET;

public class BruteForceAuthoring : MonoBehaviour, SelectiveSystemAuthoring
{
    // add system if Authoring is used
    public Type GetSystemType() =>
          typeof(BruteForceInterestManagementSystem);
}

So far, the system is still disabled by default.

3. Add the Authoring component to the NetworkServer/NetworkClient GameObject:

When DOTSNET starts, it will scan the Hierarchy for all SelectiveSystemAuthoring components, and then create the systems specified in GetSystemType automatically.

Last updated