I’m currently developing a multiplayer battle game, where players control creatures to compete in real-time battles. The game is being developed in Unity,. I’m seeking advice on the best practices for saving and synchronizing the player’s creatures data in this context.
Game Structure
Game Context:
Each player owns a collection of creatures, with attributes such as Name, ID, Level, Attack, Defense, Speed, and others.
During a match, players select a subset (3 Creatures) to use in battle.
2* Game Flow:
Players enter matchmaking.
After matchmaking, the selected Creatures data needs to be accessible on both the server and client for:
Real-time synchronization during battles.
Displaying attributes and triggering animations.
Battles happen in real-time, with synced movement, activated abilities, and dynamically updated stats.
Multiplayer Scenarios:
Creatures data is critical for both client and server to handle battle logic.
The challenge is to avoid inconsistencies, redundant data, or performance issues during synchronization.
As you can imagine, there are multiple solutions to what you are describing, but let’s see…
I’m assuming these creatures are static * types (like, let’s say, Pokémon or TemTem), so each type can be assimilated to a Prefab, and then only their stats change (because maybe they level up or you use items on them).
(* When I say static, the opposite of that would be robots that are made of many parts, or creatures you can genetically engineer, etc.)
In this case it would be enough to store their properties in scripts attached to the Prefab, and let coherence sync them. Like always, only whoever is the authority on the Prefab can change those values.
At this point it’s worth mentioning that we can only sync basic types (full list) so for instance if your creatures have some kind of item attached to them, it might make sense to assign that item an int or string “id”, and when that is changed, act accordingly by loading the appropriate item/spell/etc.
You can listen on the non-authoritative side for these changes using the [OnValueSynced] attribute, explained here.
Sometimes when relying on automatic synchronisation is not enough, you might want to broadcast actionsusing commands (it’s our flavour of RPCs). Don’t miss out this video on authority and commands, it clarifies a few things!
Hope it’s helpful, feel free to ask more questions!