My masterclient instantiates a unit and fills its list with a few waypoints for navmeshagent walking. Any unit spawned with this method knows it is an AI because playerID is set to “none”. If playerID is “none” it automatically calls the function to walk. The function to walk starts with if masterclient or if ismine (same thing same error.) Despite this, the other client spams error messages when the unit instantiates. With google searches i’ve determined that it’s because my list is empty. This seems to be confirmed because if i put an item into the list in the inspector while the game is running then the error stops. The contents of the list should only matter to the masterclient, and the units do walk properly on both clients. But i get a million errors per frame that read:
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[UnityEngine.Transform].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
UnitCapabilities.Update () (at Assets/Scripts/UnitCapabilities.cs:110)
void SpawnCreep () {
if (PhotonNetwork.isMasterClient == true) {
GameObject newCreep = PhotonNetwork.InstantiateSceneObject ("Creep", transform.position, Quaternion.identity, 0, null) as GameObject;
newCreep.name = "Wubaluba";
newCreep.GetComponent<UnitCapabilities> ().playerID = "none";
foreach (Transform waypoint in waypoints) {
newCreep.GetComponent<UnitCapabilities> ().points.Add (waypoint);
//newCreep.GetComponent<UnitCapabilities> ().photonView.RPC("AddPoint", PhotonTargets.All, waypoint);
}
the commented section won’t work because apparently you can’t send transforms through rpc.
void Start () {
if (playerID == "none") {
if (PhotonNetwork.isMasterClient)
GoToNextPoint ();
}
}
void GoToNextPoint() {
if (this.photonView.isMine) {
if (points.Count == 0)
return;
Debug.Log ("gotonextpoint");
if (Vector3.Distance (points [0].position, transform.position) > 2f) {
agent.destination = points [0].position;
}
}
}
The debug log “gotonextpoint” is not called on the 2nd client, but the 2nd client is spamming errors. So confused pls help.