- Home /
Optimize Having Thousands of GameObjects
Okay, I know this question has been answered before, but it's always something like "Just batch it," But I have thousands of trees, rocks, and plants that are harvest-able in my game.
As of now, when loading play-mode, it takes about twenty seconds, that's completely unacceptable.
I have another part of my map which is 10x bigger, and I need to fill that with trees and rocks as well, but I cannot merge these into one object, they all need to be cut down by the player.
This is not a performance issue, I have plenty of things controlling its scripts, but it's a loading issue. Entering play-mode takes twenty seconds, and I still need to fill the rest of the map as I said before.
So, if anyone could please help me with this, it would be greatly appreciated!
For now, I have a developer world that is just a plane with a couple objects that I can test stuff in, this takes about 1-3 seconds to load.
Thanks in advance!
Do you have everything active in the beginning? If so, split your scene into small parts and activate them when needed.
Yes, but the odd thing is that if I disable every tree, rock, and plant in the game, it still takes 20 seconds.
Someone told me that Unity sort of rebuilds every object in a virtual scene when you play it, so I think it would include the disabled objects. (Correct me if I'm wrong.)
When I think again it probably has to load a lot even if all objects are not active but it should have some impact. Is the load time still that big when you build and run the game?
You could try to save the little parts as prefabs and instantiate them when needed. I haven't tested that with that big levels though, but I believe the big games load the scene from disc part by part as you proceed in game. $$anonymous$$aybe there is a better way than instantiate, but you anyway might want to split your scene to smaller parts by some logic.
Do you really have to have all those GameObject present at all times? Would it be possible to load them in and out of memory, when the player is near them/looks towards their direction?
Also, do all these objects really have to be seperate? If you have 100 rocks which are individually harvestable, couldn't you have one "rock manager" object which contains the harvest-specific data for each rock (I guess something like damage and $$anonymous$$erals left), and represent the rocks via one mesh (possibly chunked if you go over the 65k vertices limit)? If the player picks at one rock, the rock's id would be used as the key to a dictionary on the rock manager which returns the rock data as the dictionary value.
Sorry for the late reply, but yes, I do have to have them present at all times, and the game already uses a decent amount of memory.
How would I do the rock manager and tree manager thing? that would save my life!