Immense Lag With a Huge Amount Of GameObjects But All of the meshes and colliders are turned off..

Game Story :
So I’m working on a game, Trying to make a random world generation. So far so good though I fear If I increase the world size the game will brake as it already lags when having for example 5k Tiles. So I worked on a render script. Worked good as well, as it fixed the world size limitations and increased it to 7k. But now with over 7k tiles the game freezes at the moment the renders the tiles. I don’t know If this is the fault of the overload of tile gameobjects or due to the render having an error in the render script as it is flawless.

First question :
-It seems that when doing loops the timestamp freezes? as it can take about 7 to 8 seconds to create the world but when doing the script timestamp method it says about 4 seconds.

Second Question:
-Does having a bunch of disabled Gameobjects create an overload on the RAM or CPU ? As I only have the Gameobject asset referenced. Searched for some reasons to RAM overusage and it says the referencing Meshes and Sprites and Colliders maybe be the cause but None of them are.

I see in your post a lot of speculation. This is not the way to solve performance problems.

Unity has tools for measuring and diagnosing problems with memory, cpu, rendering and more. The main tool is the profiler:

Using the profiler you can deduce for sure whether you have an issue caused by scripts, by memory, or by rendering. No guessing or speculation required.

2 Likes

We don’t either. Attach the profiler and find out.

Generally the answer to almost all game performance issues is to just do less, or to spread the workload out in time.

If you DO have a performance problem, there is only ONE way to find out. Always start by using the profiler:

Window → Analysis → Profiler

Failure to use the profiler first means you’re just guessing, making a mess of your code for no good reason.

Not only that but performance on platform A will likely be completely different than platform B. Test on the platform(s) that you care about, and test to the extent that it is worth your effort, and no more.

https://discussions.unity.com/t/841163/2

Remember that optimized code is ALWAYS harder to work with and more brittle, making subsequent feature development difficult or impossible, or incurring massive technical debt on future development.

Notes on optimizing UnityEngine.UI setups:

https://discussions.unity.com/t/846847/2

At a minimum you want to clearly understand what performance issues you are having:

  • running too slowly?
  • loading too slowly?
  • using too much runtime memory?
  • final bundle too large?
  • too much network traffic?
  • something else?

If you are unable to engage the profiler, then your next solution is gross guessing changes, such as “reimport all textures as 32x32 tiny textures” or “replace some complex 3D objects with cubes/capsules” to try and figure out what is bogging you down.

Each experiment you do may give you intel about what is causing the performance issue that you identified. More importantly let you eliminate candidates for optimization. For instance if you swap out your biggest textures with 32x32 stamps and you STILL have a problem, you may be able to eliminate textures as an issue and move onto something else.

This sort of speculative optimization assumes you’re properly using source control so it takes one click to revert to the way your project was before if there is no improvement, while carefully making notes about what you have tried and more importantly what results it has had.

@Kurt-Dekker @PraetorBlue Thank you for your suggestions But Once I Activate the profiler tab the whole game starts freezing and the framerates harshly fall. Don’t know the cause of this. I can send A Photo Of it if you guys would like to see what it shows as I personally don’t understand it.

When I talked about the render script it was to reduce the overload of active gameobjects in the scene. A script that only activates the gameobjects in a certain radius. It indeed reduced the overload, but the higher the world size is the much lag I receive wich is not making sense as the render script only render for example 100 tiles around the player leaving all other tiles unrendered(disabled). Tried to make the render script destroy those gameobjects but the delay and lag at the destruction of them makes it unbearable.

Sorry if I’m focusing on the render script too much but it is because I don’t understand why 100 tiles active lag the game in a 5000 tiles unrendered world. While in an lets say 500 tiles world 100 rendered tiles run so smooth.

Btw the tiles structures also have animations…But AGAIN they all are disabled…
Also I’m probably going to make this game for pc only (windows only) as I don’t know If I’m ready to do some crossplatform coding. Also The game will be offline.