#Not Serializing Network List right

1 messages · Page 1 of 1 (latest)

patent glen
#

I was following a tutorial from code monkey where he makes a network list and seralizes it as shown in the pictures. But when i do this i get a Object refrence not set to an instance of an object. I'm not sure if im initializing the list or serializing it wrong so any help would be appreciated 🙂

stoic shuttle
#

I wouldn't use a singleton with networking. They tend to get overwritten when objects spawn.

I would use NetworkVariable<Dictionary<int,PlayerData>>() instead of network list

patent glen
# stoic shuttle I wouldn't use a singleton with networking. They tend to get overwritten when ob...

NullReferenceException: Object reference not set to an instance of an object
GameMultiplayer.NetworkManager_OnClientConnectedCallback (System.UInt64 clientId) (at Assets/Scripts/UI/MainMenu/GameMultiplayer.cs:88)
private void NetworkManager_OnClientConnectedCallback(ulong clientId)
{
playerDataNetworkDic.Value.TryAdd(clientId, new PlayerData
{
clientId = clientId,
modelID = 0,//GetFirstUnusedColorId(),
});
Im still confused on the null refrence my playerDataNetworkDic. do i need to initialize it once the game activates?

stoic shuttle
#

Yes the dictionary need to be initialized along with the network variable

patent glen
stoic shuttle
patent glen
# stoic shuttle You can initialize it in line. `NetworkVariable<Dictionary<int,PlayerData>>Playe...

hey sorry 😅
NullReferenceException: Object reference not set to an instance of an object
GameMultiplayer.NetworkManager_OnClientConnectedCallback (System.UInt64 clientId) (at Assets/Scripts/UI/MainMenu/GameMultiplayer.cs:88)

I called it like this

private NetworkVariable<Dictionary<ulong, PlayerData>> playerDataNetworkDic = new NetworkVariable<Dictionary<ulong, PlayerData>>(new Dictionary<ulong, PlayerData>());

this was super easy for me to setup in the past so im super confused. On this null ref might have to give it up in a second to stop bothering you lol.

stoic shuttle
patent glen
#

yeah it doesnt after some testing i realized im a dummy i think its running to fast when the game first starts is their a good way i should be delaying or calling this?

stoic shuttle
patent glen
#

yes NetworkManager.Singleton.OnClientConnectedCallback += NetworkManager_OnClientConnectedCallback;

#

and than i want to add the player data when they join the game

stoic shuttle