Nested Foreach Loop is freezing/crashing Unity.
Hi,
I am attempting to create a list of classes. These classes have categories. Each class within the same category can have a "Rival" of that same category.
I am using a nested foreach statement to find each class that is in my category and is not myself. The classes are rather large and have a lot of inheritence, so i don't know if Unity just can handle this much data, or i have some sort of error in my code that tunnel vision is blocking.
The Function that is crashing
private void SetRivals()
{
foreach (Network network in Networks)
{
List<Network> matches = new List<Network>();
foreach (Network target in Networks)
{
if(target.Category == network.Category)
{
if(target != network)
{
matches.Add(target);
}
}
}
network.SetPossibleRivals(matches);
}
}
The Function being targetted
public void SetPossibleRivals(List<Network> matches)
{
PossibleRivals.AddRange(matches);
}
If needed, i can post the whole Class.
Thanks in advance!
Your answer
Follow this Question
Related Questions
unity crashes when i run a empty foreach loop 0 Answers
Application.TickGlobalCallbacks causing crashing! 0 Answers
Editor freezes after 'killing' an enemy but not every time 1 Answer
How can I simplify a nested foreach 1 Answer
Function runs fine the first time but crashes if I run it twice? 1 Answer