Need help using 16000+ Game Objects

Hi, I’m making a 2D game that uses 16K+ gameobjects (blocks) (instantiated at runtime). It’s clear that with that many gameobjects will cause things to get slow, so I tried parenting each block to a container object with only a collider, and using a trigger around the player to activate the nearest blocks. This works fine since I only have about 100 blocks activated at a time, but only when I use about 2000 blocks. Once I crank it up to my desired 16000, whenever the trigger calls
collider.transform.GetChild(0).gameObject.SetActive(true);, the game hangs for a split second, causing moving to be jittery.

I’ve tried everything from disabling a few components on the block, but it’s clear that the problem is Unity having to keep track of so many blocks. I’ve thought about storing the Vector2s inside an array and checking their position inside of a Rect but I don’t think anybody’s device is up to looping through 16K items every few frames.

Any suggestions please?

My suggestion to you would be: Don’t put that many objects in the scene at one time. You should focus on how many objects you absolutely need at any given time, based on how many are in view, and then just use relatively small identifiers (GUIDs, for example) to store the information about the blocks that are not currently loaded, so that their data can be fetched when they are needed.

This is how most games manage data, and in fact isn’t too far off from how OpenGL and DirectX manage to not get bogged down rendering extra junk that isn’t on screen, or even stuff that isn’t visible (rendering front-to-back, so as not to render pixels that are obstructed by something else that will need to be rendered, anyway), when used properly.

I would make a “pool” of active GameObjects with a script attached to them. The pool should be sufficiently large to cover the area that is needed.

Do not destroy or create new GameObjects at runtime, simply change the data attached to them, and change them as needed so that the same GameObject can represent a multitude of blocks, switching when the older block is no longer needed, and a new block is needed.