miwarnec / DOTSNET

Public DOTSNET issue tracker
20 stars 0 forks source link

Allow prefab system to register Archetypes #6

Open vipvex opened 4 years ago

vipvex commented 4 years ago

Currently the only way to create entities on clients/servers is to use the prefab system with the entity conversion workflow. However many projects don't use the Entity conversion workflow. And will likely not use them in the future as unity creates an Entity editor in the project.

In my project I create entities using Archetypes that I pre-define like in this example:

Archetypes.cs

public static class Archetypes
{
   public static readonly ComponentType[] Civilizaiton = new ComponentType[]
    {
        typeof(CivTag),
        typeof(PlayerMember)
    };

    public static readonly ComponentType[] Player = new ComponentType[]
    {
        typeof(PlayerTag),
    };

    public static readonly ComponentType[] WarriorComponents = new ComponentType[]
    {
        typeof(Translation),
        typeof(Rotation),
        typeof(Scale),
    }
   // Etc,
}

And to spawn them I just call

EntityManager.Instantiate(Archetypes.Warrior) // Pseudo code

This way of working is super clear and simple and I know exactly what components each entity type might have.

However with the current DOTNETS I have to create a GameObject prefab and then an Authoring component. And then add it to the prefab system.

My suggestion is to create a method to register an archetype. Such as:

PrefabSystem.RegisterArchetype(Archetypes.Warrior); PrefabSystem.RegisterArchetype(Archetypes.Civilization)

And that would do exactly what the Authoring & Prefab systems do -- add NetworkEntity components etc.

But this way we don't have to create GameObjects etc.

miwarnec commented 4 years ago

Sorry for late reply, was busy with transports :) Yep, it makes perfect sense. Will do.

miwarnec commented 4 years ago

@vipvex in case of spawning archetypes, how would you create a pure ECS archetyp with a 3D mesh in the Editor? is that even possible right now?

AdamClements commented 4 years ago

My 2c worth - In my project the RenderMesh is then added with entitymanager.AddSharedComponentData(entity, GenerateRenderMesh(...)). I'm not sure you can do it directly with archetypes given that you need to actually instantiate shared mesh data and all an archetype gives you is the list of component types... and given that, wouldn't it make more sense to just sync a given set of components directly and skip out the extra layer of indirection as archetypes aren't the only way to instantiate an entity (I rarely use it in fact).

I would much rather I could tag specific component types to be synced from server to client (possibly even instead of the NetworkEntity component...) and then mirror entities with the common components simply appear on the client side - ridiculously simple to understand.

Then for rendering you would actually set up a client side system that simply ran on entities that had e.g. the Warrior component, but no RenderMesh component, thus picking up any newly spawned entities that hadn't had their render mesh attached yet. This would be nicely future proof against future changes to the rendering framework etc. and remove the need to set up explicit mappings and new structures (it would also be really quick for new people getting started in terms of just seeing entities appear in the ClientWorld with the right properties, even if they're not rendering yet)

xentripetal commented 3 years ago

As a dependent of this, I think the requirement of a translation and rotation on SpawnMessage's should be removed once this is implemented. It would be useful to have networked entities using the built in lifecycle handling that don't have to be presentation entities.