I’m just trying to get all float values from 5 different list of floats from client to the server, and server to the client. I need these 5 lists of floats, all created from user input, so that I can be able to manipulate them.
However, I’m getting all sorts of weird errors.
This is the error message I am getting:

The initialization code is there. Initialize() runs fine.
And this is the most interesting bit:
healthPrefabSyncList is not null.
Yet, it reports an error saying the SyncList isn’t initialized.
I’m confused by this.
Should I report a bug for this? I feel the error message is misleading me, or it’s something else that I’m misled to believe it’s not initialized.
Any suggestions?
Full code is given below:
using UnityEngine;
using UnityEngine.Networking;
using System.Collections.Generic;
using System;
public class UnitAttributes : NetworkBehaviour {
public List<float> healthPrefabList;
public List<float> attackPrefabList;
public List<float> speedPrefabList;
public List<float> mergePrefabList;
public List<float> splitPrefabList;
public SyncListFloat healthPrefabSyncList;
public SyncListFloat attackPrefabSyncList;
public SyncListFloat speedPrefabSyncList;
public SyncListFloat mergePrefabSyncList;
public SyncListFloat splitPrefabSyncList;
public void Awake() {
this.Initialize();
}
public void Initialize() {
if (this.healthPrefabList == null) {
this.healthPrefabList = new List<float>(10);
}
if (this.attackPrefabList == null) {
this.attackPrefabList = new List<float>(10);
}
if (this.speedPrefabList == null) {
this.speedPrefabList = new List<float>(10);
}
if (this.mergePrefabList == null) {
this.mergePrefabList = new List<float>(10);
}
if (this.splitPrefabList == null) {
this.splitPrefabList = new List<float>(10);
}
if (this.healthPrefabSyncList == null) {
this.healthPrefabSyncList = new SyncListFloat();
this.healthPrefabSyncList.Callback = this.OnSomethingChanged;
}
if (this.attackPrefabSyncList == null) {
this.attackPrefabSyncList = new SyncListFloat();
this.attackPrefabSyncList.Callback = this.OnSomethingChanged;
}
if (this.speedPrefabSyncList == null) {
this.speedPrefabSyncList = new SyncListFloat();
this.speedPrefabSyncList.Callback = this.OnSomethingChanged;
}
if (this.mergePrefabSyncList == null) {
this.mergePrefabSyncList = new SyncListFloat();
this.mergePrefabSyncList.Callback = this.OnSomethingChanged;
}
if (this.splitPrefabSyncList == null) {
this.splitPrefabSyncList = new SyncListFloat();
this.splitPrefabSyncList.Callback = this.OnSomethingChanged;
}
}
public override void OnStartClient() {
GameObject content = GameObject.FindGameObjectWithTag("Content");
if (content != null) {
Attributes attr = content.GetComponent<Attributes>();
if (attr != null) {
attr.unitAttributes = this;
Debug.Log("Unit attributes set successfully.");
for (int i = 0; i < 5; i++) {
for (int j = 0; j < Attributes.MAX_NUM_OF_LEVELS; j++) {
switch (i) {
case 0:
this.healthPrefabList.Add(1f);
break;
case 1:
this.attackPrefabList.Add(1f);
break;
case 2:
this.speedPrefabList.Add(1f);
break;
case 3:
this.mergePrefabList.Add(3f);
break;
case 4:
this.splitPrefabList.Add(3f);
break;
}
}
}
}
}
}
public void UpdateValues() {
if (!this.hasAuthority) {
this.UpdateListValues();
return;
}
CmdUpdateValues();
}
[Command]
public void CmdUpdateValues() {
RpcUpdateValues();
}
[ClientRpc]
public void RpcUpdateValues() {
Debug.Log("Writing values.");
while (this.healthPrefabSyncList.Count < this.healthPrefabList.Count) {
this.healthPrefabSyncList.Add(0f);
}
for (int i = 0; i < this.healthPrefabList.Count; i++) {
this.healthPrefabSyncList[i] = this.healthPrefabList[i];
Debug.Log("Value: " + this.healthPrefabList[i] + " Sync Value: " + this.healthPrefabSyncList[i]);
}
while (this.attackPrefabSyncList.Count < this.attackPrefabList.Count) {
this.attackPrefabSyncList.Add(0f);
}
for (int i = 0; i < this.attackPrefabList.Count; i++) {
this.attackPrefabSyncList[i] = this.attackPrefabList[i];
}
while (this.speedPrefabSyncList.Count < this.speedPrefabList.Count) {
this.speedPrefabSyncList.Add(0f);
}
for (int i = 0; i < this.speedPrefabList.Count; i++) {
this.speedPrefabSyncList[i] = this.speedPrefabList[i];
}
while (this.mergePrefabSyncList.Count < this.mergePrefabList.Count) {
this.mergePrefabSyncList.Add(0f);
}
for (int i = 0; i < this.mergePrefabList.Count; i++) {
this.mergePrefabSyncList[i] = this.mergePrefabList[i];
}
while (this.splitPrefabSyncList.Count < this.splitPrefabList.Count) {
this.splitPrefabSyncList.Add(0f);
}
for (int i = 0; i < this.splitPrefabList.Count; i++) {
this.splitPrefabSyncList[i] = this.splitPrefabList[i];
}
Debug.Log("Updating value.");
for (int i = 0; i < this.healthPrefabList.Count; i++) {
this.healthPrefabList[i] = this.healthPrefabSyncList[i];
}
for (int i = 0; i < this.attackPrefabList.Count; i++) {
this.attackPrefabList[i] = this.attackPrefabSyncList[i];
}
for (int i = 0; i < this.speedPrefabList.Count; i++) {
this.speedPrefabList[i] = this.speedPrefabSyncList[i];
}
for (int i = 0; i < this.mergePrefabList.Count; i++) {
this.mergePrefabList[i] = this.mergePrefabSyncList[i];
}
for (int i = 0; i < this.splitPrefabList.Count; i++) {
this.splitPrefabList[i] = this.splitPrefabSyncList[i];
}
}
public void UpdateListValues() {
for (int i = 0; i < this.healthPrefabList.Count; i++) {
this.healthPrefabList[i] = this.healthPrefabSyncList[i];
}
for (int i = 0; i < this.attackPrefabList.Count; i++) {
this.attackPrefabList[i] = this.attackPrefabSyncList[i];
}
for (int i = 0; i < this.speedPrefabList.Count; i++) {
this.speedPrefabList[i] = this.speedPrefabSyncList[i];
}
for (int i = 0; i < this.mergePrefabList.Count; i++) {
this.mergePrefabList[i] = this.mergePrefabSyncList[i];
}
for (int i = 0; i < this.splitPrefabList.Count; i++) {
this.splitPrefabList[i] = this.splitPrefabSyncList[i];
}
}
public void OnSomethingChanged(SyncListFloat.Operation op, int index) {
Debug.Log("Testing this: " + index);
}
}


