Search Unity

SyncList - How to? Weird Error

Discussion in 'Multiplayer' started by Saikred, Jun 29, 2015.

  1. Saikred

    Saikred

    Joined:
    Oct 30, 2014
    Posts:
    3
    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):
    Code (CSharp):
    1. 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.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. using UnityEngine.Networking;
    5. using System.Collections.Generic;
    6.  
    7. public class NetworkingPlyList : NetworkBehaviour {
    8.    
    9.     public struct PlyData
    10.     {
    11.         public string PlayerName;
    12.         public string PlayerAddress;
    13.         public string PlayerPort;
    14.         public bool Connected;
    15.         public string GUID;
    16.         public string NetworkID;
    17.         public bool Host;
    18.  
    19.         public PlyData( string Name , string Addy , string Port , bool PlayerConnected , string Guid , string Nwid , bool IsHost )
    20.         {
    21.             PlayerName = Name;
    22.             PlayerAddress = Addy;
    23.             PlayerPort = Port;
    24.             Connected = PlayerConnected;
    25.             GUID = Guid;
    26.             NetworkID = Nwid;
    27.             Host = IsHost;
    28.         }
    29.     }
    30.  
    31.     public class SyncListPlyData : SyncListStruct<PlyData>
    32.     {
    33.        
    34.     }
    35.    
    36.     public SyncListPlyData PlayerConnectionList = new SyncListPlyData();
    37.  
    38.    
    39.     public void PrintPlayers() {
    40.         Debug.Log( "Printing Players" );
    41.         foreach ( PlyData Ply in PlayerConnectionList )
    42.         {
    43.             Debug.Log( "PlyConnectionData[[  Players Address= " + Ply.PlayerAddress + ":" + Ply.PlayerPort + "  GUID: " + Ply.GUID + "  NetworkID: " + Ply.NetworkID + "  Connected: " + Ply.Connected + "  IsHost: " + Ply.Host );
    44.         }
    45.     }
    46.  
    47.     public void AddPlayer( string Name , string Addy , string Port , string Guid , string Nwid , bool IsHost )
    48.     {
    49.         print( "Adding Ply to this list inside NetworkingPlyList" );
    50.         PlayerConnectionList.Add( new NetworkingPlyList.PlyData( Name , Addy , Port , true , Guid , Nwid , IsHost ) );
    51.     }
    52.     // Use this for initialization
    53.     void Start () {
    54.    
    55.     }
    56.    
    57.     // Update is called once per frame
    58.     void Update () {
    59.    
    60.     }
    61. }
    62.  
     
  2. Hacky

    Hacky

    Joined:
    Mar 22, 2013
    Posts:
    28
    May be yu should't extend from SyncListStruct<>. Why don't you use SyncListStruct<> directly?
     
  3. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    what makes you think that error has anything to do with SyncList? It looks like an exception in the profiler?
     
  4. Saikred

    Saikred

    Joined:
    Oct 30, 2014
    Posts:
    3
    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.
     
    Last edited: Jun 29, 2015
  5. Hacky

    Hacky

    Joined:
    Mar 22, 2013
    Posts:
    28
    I don't think is a profiler failure. It looks like you didn't start the network. It's only a guess.
     
  6. rich_seabirdsim

    rich_seabirdsim

    Joined:
    Jan 28, 2014
    Posts:
    4
    I had the same error, and it was because I didn't start the network.
     
  7. turnipinrut

    turnipinrut

    Joined:
    Oct 27, 2014
    Posts:
    13
    I had this error because i was instancing the networkManager in awake, could be something similar.
     
  8. chrismcmath

    chrismcmath

    Joined:
    May 13, 2014
    Posts:
    3
    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.
     
  9. bombsquare

    bombsquare

    Joined:
    Oct 29, 2014
    Posts:
    8
    If you derived from NetworkManager, make sure you do not use Awake() there. It may lead to the error message you met.
     
  10. jethrogillgren

    jethrogillgren

    Joined:
    Jan 11, 2017
    Posts:
    28
    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
     
  11. unity_Vf94ggq9R0gE7w

    unity_Vf94ggq9R0gE7w

    Joined:
    Sep 26, 2018
    Posts:
    2
    Set port before NetworkTransport.Init() like:

    NetworkManager.singleton.networkPort = 7777;

    NetworkTransport.Init();