Optimizing a massive array of GameObjects pls help

Hi! So this is the first time I’ve ever really started a unity project with the intent to finish it, and so what my plan is is to make a game similar to Factorio. I have a 10,000 by 10,000 array to hold values for the map (It’s an array of instances of a class called Tile, with IDs and other info) This works great, and I’ve got some nice ore generation going. It’s pretty fast, too. However, the problem is when I go to instantiate images where the Tiles are. There can be many millions of tiles generated in the world, and so iterating through a List of the coordinates of every tile on startup is impractical. At this point, I don’t know how Unity would handle that many GameObjects in a scene, even if they’re not technically rendered. I was thinking of instantiating new GameObjects when the camera moves, and destroying the GameObjects when they are out of view, but this seems to cause gameplay lag.
Can anyone help me with a solution?

So yeah handling 100.000.000 objects can be a bit demanding. In this case I would setup a couple systems to not handle everything all the time.

Because you don’t want to loop through an enormous array, you need to implement something like chunks. The chunks minecraft uses are a great example. When the player is a certain distance away, load the chunk. Or when you preload a lot of stuff before the game, set the chunk active. This will greatly reduce the complexity because you are handling 10.000 chunks instead of 100M objects. Those can be stored in a 100x100 array. That’s a bit more manageable already.

So to access a tile now, you need to write a function that converts the id of the clicked tile to a chunk/tile id. So something like: clicked ID (155, 122). Mathf.FloorToInt(155 / width) = 15. 155%width = 5. So you know its the 15th chunk to the right and the 5th tile in the chunk. And ofcourse do the same for the y coordinate.

In case you have a lot of different tile images, you might want to think about categorizing the tiles. So lets say you have 1000 different tiles, you don’t want to loop through each time to find a picture for your tile. If you group them to idk roads, trees, buildings and add that identity to your tile, you can get that array to 50 elements, saving some processing time. Because you are dealing with so many object, every improvement has a great impact.
Just an idea, maybe using an object is a good way to go. You can access information using the key:value pair. So you don’t have to loop but just use object.objectName or object[‘objectName’]. For example: When you store all your images in an object and you scan a tile and get the type (bigTree e.g.) you just get the image by typing myImageObject[‘bigTree’]. Never tried it but might be a good way to go.
I apologize in advance for how this message looks, but for some reason I cant add linebreaks or codeblocks or any styling for that matter, so this is it. Hope this gives you some ideas.