x


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?

more ▼

asked Dec 17 '11 at 02:55 PM

benjaben gravatar image

benjaben
31 11 13 15

7500 isn't that many; I guess the issue is with what you're doing exactly.

Dec 17 '11 at 03:36 PM Eric5h5

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

Dec 17 '11 at 04:21 PM benjaben

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!)

Dec 17 '11 at 08:34 PM flamy
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Dec 17 '11 at 08:45 PM

Owen Reynolds gravatar image

Owen Reynolds
11.6k 1 7 45

Thank you for your input. I'm so used to having everything GameObject based that just using programming seems strange haha.

Dec 20 '11 at 05:29 PM benjaben
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x29

asked: Dec 17 '11 at 02:55 PM

Seen: 813 times

Last Updated: Dec 20 '11 at 05:29 PM