Hi,
I have begun exploring the possibilities of Unity Networking, and it’s best practices/common use. What I have found is, that both Unet and plugins such as Photon heavily rely (and expect) that you will be syncing GameObject components such as transforms and MonoBehaviors.
However, suppose the following game architecture philosophy: GameObject is a visual representation of a non-MonoBehavior class (which makes core gameplay logic classes considerably more lightweight).
Example:
- MeleeWeapon (which is a Weapon, which is an Entity) class has some information about itself such as, I dunno, gold value, level, damage, speed, quality of it’s parts etc etc
- MeleeProp (which is a Prop) is a MonoBehavior script on a pooled GameObject which accepts a Weapon type and changes GO’s mesh renderer or textures or materials or whatever, to accurately represent given Weapon instance.
Given this approach, the network-aware classes should be the non-MB(MonoBehavior) ones (Entity and descendants), not MB classes such as Props as these are created locally and do not need to be synced. What is the best approach to solve this?
In other words, what would be adequate replacement for SyncVars, Commands and RPCs in non-MB classes? The concept and indeed, implementation of SyncVars and RPCs in NetworkBehaviors is very well done, but how can we use this for non-Monobehavior objects?
Or am I completely going the wrong way about this? What is the usual approach in this scenario, if that’s the case?
EDIT:
I wish to clarify what I’m trying to achieve. In short, I wish to sync non-MonoBehavior classes across network.
What Unity currently does:
What I need to do:
As you can see I’m trying to avoid replication of resource-heavy GameObjects (or MonoBehavior components), and instead come up with a universal system for syncing some network-aware classes. Only the Network component is synced, and can (but doesn’t have to) be a MonoBehavior.
I will come up with a pseudo-code prototype shortly, in the meantime, if you already know of a plugin or a native Unity method to achieve this, please do share your ideas! Otherwise, I’m prepared to come up with my own system built simply on nothing but Transport layer.
I got some code ideas up. Please let me know if this is at least half-way decent approach.
3451064–273449–Network.cs (1.51 KB)
3451064–273450–Player.cs (2.57 KB)