- Home /
Managing a large list of objects
I am using the List class to store a large amount of nodes for my pathfinding grid. However if I try to go above about 7,500 objects in the List Unity almost completely freezes up. Would there be a more efficient way to keep track of this many objects?
7500 isn't that many; I guess the issue is with what you're doing exactly.
I have Node objects in the list. Each node object has a Node.cs script attached to them and thats it. I'm really not sure what it freezes so bad
most of the freezing problems in unity can be fixed by moveing the code tht freezes to a seperate thread!! it worked for me in most cases!!(unless it is a infinite loop!)
Answer by Owen-Reynolds · Dec 17, 2011 at 08:45 PM
I'd guess that many gameObjects could be the problem, when you probably don't need them to be. Could make node be a regular class (no inherit from MonoBehavior) and create it the normal programming way:
LinkedList<Node> N;
N = new LinkedList<Node>(7500);
for(int i=0;i<7500;i++) {
N[i] = new Node();
// math to set node values from whatever
}
If you actually have 7500 gameObjects, that people have hand-entered data into, you can still suck that into the Nodes at run-time and delete them.
Also, a List is good for fast anywhere inserts&deletes and OK for going from front to back. It's pretty awful for looking in spot i (for example, if Node 106 links to 390 and 5602.) For random access like that, an array is much faster.
Thank you for your input. I'm so used to having everything GameObject based that just using program$$anonymous$$g seems strange haha.