SyncList - How to? Weird Error

Hi there,

I’m trying to work out and get a List & Struct to sync but im getting a really weird error when i try to add data into the list.

When ever this line(50): PlayerConnectionList.Add( new NetworkingPlyList.PlyData( Name , Addy , Port , true , Guid , Nwid , IsHost ) );
I get the error:

If anyone could advise me on what I’m doing wrong it would be extremely helpful as I’m completely lost currently.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Networking;
using System.Collections.Generic;

public class NetworkingPlyList : NetworkBehaviour {
   
    public struct PlyData
    {
        public string PlayerName;
        public string PlayerAddress;
        public string PlayerPort;
        public bool Connected;
        public string GUID;
        public string NetworkID;
        public bool Host;

        public PlyData( string Name , string Addy , string Port , bool PlayerConnected , string Guid , string Nwid , bool IsHost )
        {
            PlayerName = Name;
            PlayerAddress = Addy;
            PlayerPort = Port;
            Connected = PlayerConnected;
            GUID = Guid;
            NetworkID = Nwid;
            Host = IsHost;
        }
    }

    public class SyncListPlyData : SyncListStruct<PlyData>
    {
       
    }
   
    public SyncListPlyData PlayerConnectionList = new SyncListPlyData();

   
    public void PrintPlayers() {
        Debug.Log( "Printing Players" );
        foreach ( PlyData Ply in PlayerConnectionList )
        {
            Debug.Log( "PlyConnectionData[[  Players Address= " + Ply.PlayerAddress + ":" + Ply.PlayerPort + "  GUID: " + Ply.GUID + "  NetworkID: " + Ply.NetworkID + "  Connected: " + Ply.Connected + "  IsHost: " + Ply.Host );
        }
    }

    public void AddPlayer( string Name , string Addy , string Port , string Guid , string Nwid , bool IsHost )
    {
        print( "Adding Ply to this list inside NetworkingPlyList" );
        PlayerConnectionList.Add( new NetworkingPlyList.PlyData( Name , Addy , Port , true , Guid , Nwid , IsHost ) );
    }
    // Use this for initialization
    void Start () {
   
    }
   
    // Update is called once per frame
    void Update () {
   
    }
}

May be yu should’t extend from SyncListStruct<>. Why don’t you use SyncListStruct<> directly?

what makes you think that error has anything to do with SyncList? It looks like an exception in the profiler?

Because if I comment out line 50, which is adding the object, i get no errors at all, and everything else works perfectly.

I’ve tryed a few combinations including what i would believe is what you mean by the above. but nothing is making a difference for me.

I don’t think is a profiler failure. It looks like you didn’t start the network. It’s only a guess.

I had the same error, and it was because I didn’t start the network.

I had this error because i was instancing the networkManager in awake, could be something similar.

Had the same symptoms recently that resolved to the Awake function in my derived NetworkManager hiding the initialisation of the singleton in the base.

Unforunately Awake is private in NetworkManager, so cannot be readily used in any derivation.

If you derived from NetworkManager, make sure you do not use Awake() there. It may lead to the error message you met.

Note I had the same problem with Awake as the others. Even if your Awake if empty, it will cause these errors. Deleting the function fixes the problem. It was the Awake in my derived NetworkManager that was causing it, and for me the problem started sometime between 2017.2 and 2017.3.1p1

Set port before NetworkTransport.Init() like:

NetworkManager.singleton.networkPort = 7777;

NetworkTransport.Init();