Skip to content

Extending Arch

genar edited this page Mar 13, 2024 · 1 revision

Extending Arch is a simple undertaking. So you can easily wrap Arch in new APIs or simply write libraries and frameworks that extend Arch in some way.

For one, there is the fact that Arch is simply bare minimum, the core is clean and small. No unnecessary fuss, just what counts. On the other hand, there are countless exposed properties and the DangerousUtils.

A demonstration

As an example, almost any repo from Arch.Extended can be used. Most of them hack into Arch somehow. Let's take Arch.Persistence as an example.

public Entity Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
    // Read id
    var id = reader.ReadInt32();
    return DangerousEntityExtensions.CreateEntityStruct(id, WorldId);
}

Arch forbids the creation of Entity structs by default (to protect the user from stupid actions). But don't worry, the DangerousUtils provide enough API to work around these problems. So you can simply create a new entity struct to (de)serialize anything or...

// Create archetype
var chunks = new List<Chunk>((int)chunkSize);
var archetype = DangerousArchetypeExtensions.CreateArchetype(types.ToArray());
archetype.SetSize((int)chunkSize);

Even add whole new archetypes directly... And without any problems! Similar methods and abilities exist for all major arch classes. But be careful, you have to know what you are doing and it can get dangerous.

Clone this wiki locally