- Home /
Fixing CS1061error on NetworkList gets Null Reference Exception
I'm trying to shuffle a deck of cards for multiple players in Unity 2021.2.14f1 When NetworkManagaer.cs looks like this:
public NetworkList ShuffleOrder;
. . .
private void Awake()
{
. . .
for (int i = 0; i< 99; i++) { ShuffleOrder.Add(i); }
for (int i = ShuffleOrder.Length - 1; i > 0; i--) {
swap = UnityEngine.Random.Range(0, i);
c = ShuffleOrder[swap];
ShuffleOrder[swap] = ShuffleOrder[i];
ShuffleOrder[i] = c;
}
}
...and the players' scripts look like this:
public void Shuffle()
{
int swap;
CardInDeck c;
CommonCard thisCard = new CommonCard();
for (int i = FullDeck.Length - 1; i > 0; i--)
{
swap = NetworkManager.ShuffleOrder[i];
c = FullDeck[swap];
FullDeck[swap] = FullDeck[i];
FullDeck[i] = c;
... I get the dreaded "'NetworkManager' does not contain a definition for 'ShuffleOrder' ..."
If I remove the ShuffleOrder code from NetworkManagaer.cs and change the players' script:
for (int i = FullDeck.Length - 1; i > 0; i--)
{
swap = UnityEngine.Random.Range(0, i);
c = FullDeck[swap];
FullDeck[swap] = FullDeck[i];
FullDeck[i] = c;
NetworkManager.ShuffleOrder.Add(swap);
There is no syntax error, but at runtime I get " NullReferenceException: Object reference not set to an instance of an object" on the ShuffleOrder.Add
I would be very happy to find a fix for either problem.
Your answer
Follow this Question
Related Questions
Is it possible to make a Multiplayer (1v1) game WITHOUT hosting servers? 3 Answers
how to know that which client has left the game 2 Answers
Unity Networking cannot connect to device in other countries ? 1 Answer
What is the maximum feasible number of players in a procedural-generated, top-down 2D MMO? 1 Answer