Arch icon indicating copy to clipboard operation
Arch copied to clipboard

Entity Templates

Open genaray opened this issue 2 years ago • 4 comments

Background

Would be pretty neat if we could clone entities and its components based on a template which defines its values. Basically a way to create entities with set values. Has many advantages, can be serialized easily and is more effective in many ways.

Idea

Either:

var template = new Template(
   new Position(10,10),
   new Mesh(5, Mode.Batched),
   ...
);

var clone = world.Create(template);

Or using source generation:

[Template]
public struct PlayerTemplate{

   public Transform Transform;
   public Velocity Velocity;
   public Model Modell;
   public ...
   ....
}

var template = new PlayerTemplate(whateverData);
var clone = world.Create(template);

When we choose source generators we could even build more cool constructs around this. Like an extremely efficient identifier mechanic to clone certain templates:

[TemplateStorage]
public struct Templates{

   [Identifier("1:1")]  // Or raw ints e.g. for networking? 
   public PlayerTemplate playerTemplate;

   [Identifier("1:2")]
   public MobTemplate mobTemplate;

   [Identifier("2:1")]
   public FireGolemTemplate fireGolemTemplate;
}

var cloneByIdentifier = world.Create("1:1");
var fireGolem = world.Create("2:1");

genaray avatar Nov 27 '22 22:11 genaray

Is this feature available ?

mastertnt avatar Sep 13 '23 21:09 mastertnt

Is this feature available ?

Not yet, but its still on the roadmap :) Will probably be part of Arch.Extended with its own source-generator and persistence integration ^^

However that could still take a while (need to do query caching first), so if anyone wanna contribute... feel free to :p

genaray avatar Sep 14 '23 01:09 genaray

Svelto Ecs has interesting implementation, called Entity Descriptor's. Very robust and boilerplate (like many features in Svelto).

skelitheprogrammer avatar Feb 29 '24 01:02 skelitheprogrammer

Svelto Ecs has interesting implementation, called Entity Descriptor's. Very robust and boilerplate (like many features in Svelto).

It could look similar for Arch. But with less boilerplate code of course ^^

genaray avatar Mar 13 '24 19:03 genaray