I'm trying to send a CreateEntity packet from a server to client, but I can't figure out how to send the information about components over the network. I gave each component an ID, but then I realized I'd have to send the associated data (E.X size of entity for the transform, etc). Is the easiest way to just create an Enum of entities and have the client create the components based on what it knows about the entities? I'd prefer to not do that as it makes modding much harder.
-
\$\begingroup\$ What you're talking about is called serialization, and it's almost as broad a topic as entity-component systems. Without a lot more information on your specific needs and implementation of your ECS, any answer would be mostly handwaving. \$\endgroup\$– bcristCommented Aug 10, 2014 at 1:27
1 Answer
Serialization can be implemented in any number of ways, but I would strongly suggest that you find ways to decouple entity/component semantics from network serialization as it will make it easier as new things are added to keep them in sync.
For for creating of entities, I would have a packet that gets sent perhaps on some periodic basis that contains all entities within an area of interest radius. This packet could be sent once the player enters the game world or as objects enter/leave the interest radius. Such a packet would be a combination of necessary attributes to begin rendering the object, such as but not limited to:
- GUID
- Object Type (NPC, Dynamic Object, likely a finite list here).
- Transform (position, rotation, perhaps scale)
- Race & Gender (in case of NPCs)
With the above information alone, a game could lookup the race & gender from some client install files, determine which skeletal mesh to use, physical attributes of the entity and begin rendering it.
A client often only needs a limited view of the entity's composition, just enough to enable rendering and whatever client functionality happens to exist.