Will a large array of game objects slow my game down?

I’m working on a 2D, top-down action adventure game. It occurred to me today that it could be very useful to use a large 2D array of game objects to represent each level, where each element in the array represents an integer value on a grid used to place objects. For instance, this could be used in collision detection: the moving object could check the array elements adjacent to them, and as long as they are null, they are free to move. It could also be used as a very fast alternative to raycasting.

My concern is that these arrays could be fairly large, potentially containing hundreds or even thousands of elements. I don’t THINK that’s big enough to cause me to bump into memory issues or slow-down, but before I go about implementing it I wanted to see what other people thought. Does this idea require too much space to be viable?

Hi! This way you are talking about are made lots of games, as tetris, bomberman, etc.
In one side you have the logical part, where each index represents each thing, for example in bomberman
0: indestructible block (up down left down walls)
1: grass (bomber man can move)
2: destructible block (it can be explode)
4: bomb
5: explosion (if an explosion goes to a cell that there is a index == 2, you can destroy the content :wink:

in a similar way tetris is done, 0 for the cells without blocks, 1 with
so if you add a block, and then you check all the 2d array and you have one line all complete of 1, you can do what tetris does… eliminate the graphics of the line ( in the logical part you will put al 0, you will push down all the lines above that destroyed line, etc…)

BUT, this have 2d arrays very small, tetris might be 7 * 25, and bomberman 3030.
But you are asking for something max of 1000
1000.
Question: the map is going to be that big?? because maybe you can divide it into scenes, or you can have only rendered the 2d cell inside this big 2d cell, that the camera is seeing, i mean the portion that the camera is seeing OR only travelling the part of the 2d cell that the camera is seeing, or where the player or stuff is happening.

Anyway, 1000*1000 is too big, give it a try (better no…), 2 for i < 1000, j < 1000. and surely unity is going to crash :$.
if you have i < 100, and j < 100, it does take some few seconds, so i thing you will have to think in a walk around.

hope it helps, cheers!

Yes,very large array of game objects will definitely effect your game performance.There will be a situation where you need to check the objects in the array very frequently or atleast 3 or 4 times for a single session , this makes the game performance very low coz you can check the array using for-loop which loops the array in every index.
It is fine if you just place the gameobjects in array.If you once start checking or do some operations on the array will definitely cause performance issues.
You may get exceptions like null reference if you destroy the gameobject that belongs to array.it would be bit tough to handle these kind of issues.
Hope this may help you.
Nsks