- Home /
server and client sync
Hi Trying to make a simple networked zombie game for my school project. I've setup so you can open the game and host, then open another one and connect(so I can have one run on an empty scene and no screen etc...)
What I'm trying to do is allow people to join and then bring them up to speed about what has happened.
The game is just simple, zombies spawn from the middle of a pit and the players have to build barricades so I was thinking that letting the server spawn the zombie in the pit and using network.instantiate for that. but when a new person joins, there's no zombies in the scene. They haven't been instantiated for him yet.
How would I do so the barricades built, items changed, zombies spawned would be synced with new players?
Its quite the generalized question you ask. But I know the pitfalls when working with Unity networking quite well. If you know how to handle them its the best networking engine there is. I have made some API calls easier and automated a lot in u$$anonymous$$$$anonymous$$O: https://www.assetstore.unity3d.com/en/#!/content/13867
When a player connects, he should get the current state of game. I've no experience with networking in Unity yet, but you should learn about serialization and have a look on Photon Unity Networking. Hope that helps.
I don't have any budget unfortunately. Is there some method to instantiate objects on newly connected players? then I could set the server to make lists of all items created and instantiate the prefabs on the new client.
Haven't seen that no. Thanks for the share I started the project a while ago and had a break for a month and now I can't remember how I did with the players. if 1 player joins and moves then another one joins and he can see player 1.
Edit. I set the network view State synchronization to unreliable on the zombie and the observed target to the zombie. now when a new player joins he can see the zombies already spawned.
I'm guessing that this method is unreliable and bad for performance. But i could try and disable the sync after a player joins and have a script handle everything like animations, position, rotation etc.
Answer by MidgardDev · Jan 13, 2015 at 11:21 AM
I think there was an option with RPC calls that you could set messages on the history, that's just to let newly connected players know that there was something going on in the network before they connected.
In the documentation, you can see this page: http://docs.unity3d.com/ScriptReference/RPCMode.html that refers to the RPCModes. The option I was talking about is RPCMode.AllBuffered. This option immediately sends the message through the network but also stays buffered for when new connections or slow connections to grab the message.
This will be valid if you use Unity's builtin networking. I don't know if Photon also has this option.
It's not the best idea because a player has to load every event and recreate it ins$$anonymous$$d of loading objects and their states. It will cause overhead in both transmission of data and it's processing.
So calling that RCP function as AllBuffered and using the regular instantiate? or what would be best do you think?
Answer by sumit9236 · Jan 13, 2015 at 12:03 PM
For school project,you will use any gaming server just like photon or smartfox server.All gaming server are free to use for 100 or 50 user.Your project is school level,you easily use these server on local school system.All these server are capable to store data to server and specific data to any player.
I don't like having to rely on an external hosting tool like that. I'm also writing about the use of Unity networking so that wouldn't work for me. Thanks for the suggestion though!
Email me, I can send you a free feature-limited version (code in DLL) of my u$$anonymous$$$$anonymous$$O package (which as said uses native Unity networking and no other external libraries): http://softrare.eu/contact.html