Sending Level Data over Network

Hello.

I’m trying to send Chunkdata from a Level over the Network.

There are 256 Chunks where each is 1616. Every cube (11*1) is saved in a List.

public List<MP_Chunk> thisChunk = new List<MP_Chunk>();

The MP_Chunk class save the x, y and z Position as int, 2 bool variables and 6 Color Variables (For each side of every Cube).

public class MP_Chunk
{
	public int       x;
	public int       y;
	public int       z;
	public bool      isFloor;
	public bool      canDelete;
	
	public Color      Color_Top;
	public Color      Color_Bottom;
	public Color      Color_Left;
	public Color      Color_Right;
	public Color      Color_Front;
	public Color      Color_Back;
}

How can i send the Chunk Data for each Chunk? The Chunks are saved in a List too.

public class World_ChunkLoader : MonoBehaviour 
{
	public static World_ChunkLoader instance;
	
	public Transform ChunkObject;
	
	public int chunk_X_Width = 16;
	public int chunk_Z_Width = 16;
	
	public List<MP_Chunks> Chunks = new List<MP_Chunks>();
	
	IEnumerator Start()
	{
		instance = this;
	
		for (int x = 0; x < chunk_X_Width; x++)
		{
			for (int z = 0; z < chunk_Z_Width; z++)
			{
				MP_Chunks tempchunk = new MP_Chunks();
				tempchunk.x         = x;
				tempchunk.z         = z;
				tempchunk.isLoaded  = false;
					
				Chunks.Add(tempchunk);
			}
		}
		
		yield return StartCoroutine (World_LoadFirstChunks());
	}
	
	void FixedUpdate()
	{
		instance = this;	
	}
	
	IEnumerator World_LoadFirstChunks()
	{
		foreach(MP_Chunks Chunk in Chunks)
		{
			Transform tempFloor = Network.Instantiate(ChunkObject, new Vector3(Chunk.x * chunk_X_Width, 1, Chunk.z * chunk_Z_Width), Quaternion.identity, 0) as Transform;
			tempFloor.name      = "Chunk (" + Chunk.x.ToString () + "-" + Chunk.z.ToString () + ")";
			tempFloor.parent    = transform;
			Chunk.isLoaded      = true;
			yield return true;
		}
	}
}

public class MP_Chunks
{
	public int       x;
	public int       z;
	public bool      isLoaded;
	public Transform ChunkObj;
}

So how can i send this Data over the Network? Without a huge lag?

Any Ideas?

I tried it over Network.Instantiate, but then the meshdata for the Chunk are not loaded.

I hope u understand my question. How to send a List of information over the Network.

My Idea is, that only the Host (Server) has the level data. And on Connect or on Update it sends the Data to each Player. But i think this is to much Infromation, or?

I realy need some Help. I dont find a solution.

Man...i'm realy the only one who have Problems to send the map over a network?

1 Answer

1

Serialize your list of chunks to a byte (see this Unity Gems article if you don’t know how to do that).

RPC the byte produced (RPC supports byte)

I tried it already. The Problem is that UnityEngine.Color is not Serizable. So i can't make my List to a byte[]. Any ideas?