Hi
I’m thinking how to solve a synchronization issue on unet networking solution.
My player has certain items attached to its bones and objects, now i sync them between clients once attached, but once a player disconnects and reconnects, the enabled or disabled state doesn’t stay synced and from reading unet manual, it doesn’t have to.
So now im trying to make a state synchronization system, still trying to find help and maybe experience from people, how to solve and which way.
Any advice, experimental solutions/code is greatly appreciated.
I know that there’s basically two options i know about how to solve them, synclist and rpc sync straight from the gameobject, but still keeping my eye open for a easier or a more effective solution.
You won’t want to use RPC’s for 2 reasons
1: There are currently bugs (sometimes RPC’s aren’t received)
2: When a player reconnects the RPC isn’t called and you have no idea if something is enabled/disabled.
You will want to use Custom UNET Serialization/SyncVars/SyncList because when a player reconnects they will automatically get the latest value during OnDeserialize (occurs after Awake, but before Start). Few things to note:
1: SyncVars/SyncList would work fine for this in most cases. But they are currently buggy and can be desynchronized and hooks/callbacks can fail.
2: You can use custom serialization to avoid UNET bugs with SyncVars/SyncLists. It’s more work, but in the long run it will be more robust (at least until they fix UNET bugs).
Thank for the advice, didn’t know it was bugged. I’m currently on the verge of finishing the SyncStructList example. Going to try this out, if it doesn’t work i guess i will have to create my custom serialization method. If i get it working, i’m going to provide an example script here for other stuck with the same problem
Yeah, i got the Synclist struct kind of working, but still in progess. I made some test cases and tried them out, found that, if a host connects and starts the server, enables his gameobject, it is synced and when client later after enabling connects, it is synced with client aswell, but once the client disconnects and reconnects then the gameobject is back to disabled state. I dont know if it’s related to that bug, perhaps code missing some piece or i’m just not reseting currently since my manual overrides of network functions are not yet integrated from old system.
I have a player prefab that has multiple models to choose from. A player can select a model by clicking a button. This activates a model by ethan.setActive(true); With Rpc and Cmd this is synced to other clients, but if a client connects after the change, they don’t see it. [SyncVar] cannot be used, because the model is a GameObject.