- Home /
Server + Client NPC Syncing issue
So currently I have an MMORPG in the works. I have it set up so the Game loads a TextAsset called NPCList.txt. In the npc list it loads up the NPC ID, the position, rotation, the walkable area, and the amount in each area.
The thing is, even when I add a Network View, the Instantiated NPCs are not synced together, and are in different places. Also the bytes sent over the server are huge when it comes to a network view per NPC. (Also the NPCs wander around within the space).
I instantiate the NPCs from a Prefab in Resources, using Resources.Load. I apply the NetworkView to the prefab itself. In the coding of NPCWander and SpawnNPC there are no codes that relate to the networkview.
How would I go about syncing them together?
I think i would prefer it where the server dos the pathfinding for the NPCs, sends out the Position, rotation, animation and such. I don't want the pathfinding and set destination done on each client.
On Unity Answers people are looking for tightly defined questions and/or - you are better off posting on the forum if your question is wide ranging
well I was looking for a response like "Set the network view to do this to that, and instantiate the npcs with a script that does this... etc
It's hard to do that without something to look at. The FAQ for this site is worth reading before posting a question.
Are you creating your objects from prefabs, how are you adding networkViews to them, how do you tell the other players about the networkViews or are you relying on Network instantiate? If you have something specific, edit your question and post it.
So if you add your own network views then you need to be calling functions to associate them on different computers. You need a master controlling object somewhere that gets RPCs to tell it to create local copies and associate them. Without seeing your code I am guessing though.
Answer by Bunny83 · May 27, 2012 at 09:46 AM
Basically there are two ways of handling objects synchronization:
Only the Server / Master instantiates the prefab with Network.Instantiate. This will send a buffered RPC to all player to tell them to also create this prefab and it will link the NetworkViewID of the NetworkView so the objects are linked together. Since it's a buffered RPC, a new client will get this RPC as soon as he joins the server. Note that you have to handle all important things with buffered RPCs in this case. The LoadLevel command has also be sent with a buffered RPC so a new client first loads the level and then it creates the other objects.
The second way is more flexible but a bit more complicated. You instantiate the objects manually. The server / master send the NetworkViewIDs via RPCs to the clients and they have to match them up with the corresponding object. You have to keep track of all objects manually on the server and tell new players about them manually. In a complex game with a lot of objects i would go this way.
Thank you VERY much. It's going to be an $$anonymous$$$$anonymous$$ORPG, with well a lot of NPCs. I have different Islands. (Each island with a town and forests etc for monsters. What if i had a seperate NPC Case for each island and used the first method with Network.Instantiate? That would let me do the simple way, yet keep the NPC Count low. (Each NPC Case would appear upon teleporting to each island.
One last thing, with the Network.Instantiate do i need to attach a NetworkView to the individual NPCs?
Ok the NPCs spawn accordingly, but don't Wander accordingly. Im adding in the NPCWander script a code that basically is, if server, RPC.gotodest = decided destination. Also whats the difference between RPC$$anonymous$$ode.All and AllBuffered?
AllBuffered = sent to players even if they connect later, All = only players connected now.
Check networkview.is$$anonymous$$ine and don't path find if it is false
Your answer
Follow this Question
Related Questions
Multiplayer syncronisation 1 Answer
Network sync complicated server-client relationship 1 Answer
How do I use uNET to send client data to server (SyncListBool goes the wrong way)? 1 Answer
Server and Network no communication 1 Answer
I don't know difference between interpolation and non-interpolation 0 Answers