Hi everyone!
We’re developing a game with two modes: single-player and multiplayer. To keep it brief, here’s a quick description: the player(s) spawn in an arena where enemies (monsters) start spawning around him (them). The player controls a hero with abilities to defeat these enemies. The gameplay is enhanced with various sound effects and VFX. At any given moment, there are about 50–100 enemies on the scene alongside the hero.
Currently, sounds and effects are implemented as components added to entities. For instance, if the damage system needs to play a sound, it writes the sound ID and other necessary data into a ghost-synced component of the entity. A client-side system then reads this data and plays or stops the sounds accordingly.
Problems arise, for example, when trying to play a sound for an enemy’s death. I can’t store the sound on the enemy entity itself, as the entity will be destroyed, taking all its associated data with it. I also can’t “extend” the life of the entity just to ensure the client-side sound system has time to process it, because other systems will also process the entity during the update cycle, potentially leading to numerous bugs.
My question:
How can I properly organize “state” storage and ensure accurate data transmission between the client and server for effects or sounds? I’m looking for a general architectural solution that has been successfully applied to similar problems.
Potential solutions I’ve considered:
- Creating clone entities that “follow” the main entities throughout their lifecycle and are destroyed at the appropriate time. (I dislike this option because it involves numerous structural changes and increases the total number of entities significantly.)
- Using RPC commands to handle effects and sounds. (However, the documentation suggests RPCs aren’t intended for this purpose, and triggering 30–50 RPC commands per second doesn’t seem like a good idea.)
A small list of requirements for the system:
- It should handle sounds and effects triggered at entity creation, during the entity’s lifecycle, and immediately after the entity is destroyed.
- It must support “coordinate synchronization”: effects or 3D sounds should appear at the entity’s position.
- It should work correctly in both single-player and multiplayer modes.
Any advice or examples of architecture that effectively solve these challenges would be greatly appreciated. Thanks in advance!