- Home /
Loading many gameObjects
I am making a version of minesweeper in unity, with my own twist: instead of seeing the entire map, you control a character which sees little and tries to get as far out as possible. For this project, I need to generate a lot of gameObjects that are tiles. Currently, it isn't too difficult to load around 10,000 objects (approximately 2 seconds of loading time). However, my goal is to ideally have maps in the millions and I was wondering about the best way to do this. My best guess as to how I can reach such large map sizes is to generate the map real time. From what I've seen, unity just isn't able to handle such large amounts of objects. However, because all of the gameObjects are simple and can pretty much be described in unexplored, explored, marked and special, I hope there is a way to optimize loading times much more easily, as I am not well experienced with unity. From what I tested, it seems like the loading time comes pretty much just from the amount of objects, not how complicated these objects are (I'm sure that I can make slight optimization with code, but it doesn't seem anywhere close to enough).
Why don't you use, unity tilemap system? Then all you need to do is chunk the tiles, and render only the chunks around the player.
Answer by UnderShad · Jun 07, 2020 at 12:42 AM
The Tile system you want does not need gameobjects but Unity have a inbuild tile system where you can create your own tiles. See unity official tutorial https://www.youtube.com/watch?v=fmNtibNWPhc
But if you still need that many gameobjects you can have a scripts that reuses the gameobjects as you move around the map. See polling https://www.youtube.com/watch?v=tdSmKaJvCoA
Also Creating millions of gameobjects also means that you want to travel much further from origin where float precision limitations can mess up your game. There you have to create an illusion of infinity by relocating map to origin See https://www.youtube.com/watch?v=OaYPBSM_Uu0 After some distance everything goes back to origin. Hope it helps
Thank you for your suggestions. I have tried to use tilemaps, but had no success with them. I do not know if they can handle several functions to be placed upon them or if they can render different sprites (after opening a tile, it needs to change to show how many $$anonymous$$es are around the tile). I might try them if other solutions fail. Using object pools seems like a decent idea, however, it appears to be for loading new objects over and over again. I want to keep a path of your journey, in case you want to go back, so I'll have to still keep some objects. This suggestion might still help though. Currently I plan on simply generating the map where you are going and keeping where you went, while destroying what you have not explored. If performance becomes an issue, I might check this out. I do not know what "much further" stands for, so I hope it is more than 1000 on the x and y axis. 1000*1000 is one million, which is my desired map size. I doubt creating the illusion of infinity will work here, because I want to go back if possible.