Answer the question
In order to leave comments, you need to log in
Why is a new element not being added to the collection?
Tipo there is a collection, but elements are not added to it.
Gives an error message:
NullReferenceException: Object reference not set to an instance of an object
BoxController.OpenBox(System.Int32 BoxId) (at Assets/Scripts/BoxController.cs:102)
Brawler PPBrawler = playerStats.brawlers[Random.Range(0, playerStats.brawlers.Count)];
print(PPBrawler.Name); // PPBrawler не равен null
int count = Random.Range(Boxes[BoxId].PPAmount.x, Boxes[BoxId].PPAmount.y);
items.powerPoints.points.Add(count, PPBrawler);
PPBrawler.PowerPoints += count;
Answer the question
In order to leave comments, you need to log in
If items is list <T>, then, as far as I remember, only the element that you want to add to the list should be passed as an argument to the Add method, or there is an overload that I don’t know about.
What exactly is in line 102 of BoxController.cs? Because the error says that you are accessing an uninitialized variable (to NULL). In this case, without specifying the line numbers, it is not clear whether this can happen in a different class / line at all.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question