- Home /
Level Joining Issue
Hello all I was wondering if anyone has any ideas why I have with players and the map when they join the LAN game. So if the host starts the game and changes the map by clicking on some blocks and destroying them (like a cube game) then someone joins the game (client) they don't see the changes made to the map. However all future changes once they join are seen just fine. I even tested where server starts the game and does nothing then the client joins before any changes are made there is a perfect sync. So why does this happen? Does anyone got any ideas to this? I would really appreciate everyones help and advice. Here is the network code with what makes the cube map.
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour
{
public GameObject playerPrefab;
public GameObject snow;
public Transform spawnObject;
private bool done = false;
void OnGUI()
{
if(!Network.isClient && !Network.isServer)
{
if (GUI.Button(new Rect(Screen.width/2,Screen.height/2,100,20),"Start Server"))
{
startServer();
}
if (GUI.Button(new Rect(Screen.width/2,Screen.height/2 + 60,100,20),"Connect"))
{
Network.Connect("###.###.#.#", 25000);
}
}
}
void Awake()
{
Network.minimumAllocatableViewIDs = 20000;
}
void Update()
{
}
void startServer()
{
Network.InitializeServer(32,25000, !Network.HavePublicAddress());
if(Network.isServer)
{
for (int x = 0; x < 28; x++)
{
for (int y = 0; y > -2; y--)
{
for(int z = 0; z < 28; z++)
{
GameObject ChuckSpike = Network.Instantiate(snow, new Vector3(x, y, z), Quaternion.identity,0) as GameObject;
ChuckSpike.transform.tag = "chunk0";
}
}
}
}
}
void OnServerInitialized()
{
Debug.Log("server initialized");
spawnPlayer();
}
void OnConnectedToServer()
{
spawnPlayer();
}
void spawnPlayer()
{
Network.Instantiate(playerPrefab, spawnObject.position, Quaternion.identity, 0);
}
}
Is it loading a level, when the game starts, or client joins. Try adding a script to the blocks that looks like this:
using UnityEngine;
using System.Collections;
public class Network$$anonymous$$anager : $$anonymous$$onoBehaviour
{
void Awake()
{
DontDestroyOnLoad(gameObject);
}
void OnDisconnectedFromServer()
{
Object.Destroy(gameObject);
}
}
If that script works what is happening is, when a client joins something (presumably level loading) is causing the changes to be erased.
hmmm... that didn't seem to work but I see what you were thinking.
Answer by Carbongrip · May 04, 2014 at 09:36 PM
turns out when destroying a object you have to do this...
Network.RemoveRPCs(hit.transform.networkView.viewID);
Network.Destroy(hit.transform.root.gameObject);
if you don't then it only deletes for the users on and not future users. How ever for creating objects you just need the Network.Instantiate. Unity3d really needs to make this more clear and at least state this in the documentation for Network.Destroy.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Networked Game Issues - Camera does not follow script 1 Answer
Distribute terrain in zones 3 Answers
Error destroying player over network 1 Answer