Hello, I have a problem that I don’t understand how to solve.
I use unet to run the application over the network. I try to synchronize my list with a “SyncListStruct” type, which is in unet, but when i add my instance using the Add () method, an error occurs:
SyncList not initialized
UnityEngine.Networking.SyncList`1:Add(Cell)
Please explain the reason why this error may appear.
my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class WorldClass : NetworkBehaviour
{
public struct Cell
{
public int posX;
public int posY;
public int height;
public bool step;
public float ownerColorR;
public float ownerColorG;
public float ownerColorB;
public string build;
}
public class CellsList : SyncListStruct<Cell> {}
}
code where an error occurs
public WorldClass.CellsList cellsNet = new WorldClass.CellsList();
void iniDataWorld() {
if (isServer)
{
if (cellsNet != null && cellsData != null)
{
for (int x = 0; x < cellsData.GetLength(0); x++)
{
for (int y = 0; y < cellsData.GetLength(1); y++)
{
WorldClass.Cell cell = new WorldClass.Cell();
cell.posX = x;
cell.posY = y;
cell.height = (int)(10 * Generator.getHeight(KeyGen, x, y, 60));
cell.build = "";
int numPlayer = Random.Range(0, players.Count);
cell.ownerColorR = players[numPlayer].colorVec.x;
cell.ownerColorG = players[numPlayer].colorVec.y;
cell.ownerColorB = players[numPlayer].colorVec.z;
cellsData[x, y] = cell;
cellsNet.Add(cell); //Error
}
}
}
}
}
please, explain what I’m doing wrong. Thanks