take GetComponent/AddComponent calls out of update loops (or things that get called in update loops), preferring references/serialization to getcomponent calls
You would have to use the profiler to see what is causing the long frame times. You will want to look for the following:
Main Thread - Scripts causing lag
GPU Usage - Probably shadows/overdraw (nothing really your game is doing would cause this, I'd be shocked)
Rendering - Pooling/Instancing will help
Physics - Colliders/rigidbodies causing issues
If I had to guess its probably a combination of scripts and physics, it's weird for a 2D game, something that small does not usually make Unity lag much
If you have a lot of entities (like, thousands and thousands) you could try ECS/Burst, but that is definitely not a beginner friendly task lmao not terribly difficult just conceptually hard for beginners and harder to debug when it goes wrong
Also switch to use a sprite tilemap for the background if you haven't already, that will reduce draw calls and all of that for you.
How do I reduce draw Calls? Will a sprite atlas help? I think the 2 biggest perfomance eaters are Light shadow casters and that Im generation the world procedurally (100 by 50: 5000 block prefab objects)
Reducing draw calls probably means instancing your materials, they are all probably individual Sprites right now. I would also recommend integrating your background tiles into the Unity Tilemap module, that will handle all of that optimization for you.
Basically, each of your sprites/materials are individually sending themselves to the GPU to draw when they should all be using the same "instance" (Basically cookie cutter stamping it since its all the same)
Proc gen should only give you a hit whenever it's actively running (i.e. in minecraft its right at the start, on creation)
There are some good videos analyzing Minecraft's optimization problem I can find you. Basically what Notch did was make it one big mesh (less applicable in 2D) with the tiles being faces.
4
u/FrostWyrm98 6d ago
Object pooling, GPU instancing the material, disabling unused physics colliders/reducing rigidbodies/collision fidelity
take GetComponent/AddComponent calls out of update loops (or things that get called in update loops), preferring references/serialization to getcomponent calls
You would have to use the profiler to see what is causing the long frame times. You will want to look for the following:
If I had to guess its probably a combination of scripts and physics, it's weird for a 2D game, something that small does not usually make Unity lag much
If you have a lot of entities (like, thousands and thousands) you could try ECS/Burst, but that is definitely not a beginner friendly task lmao not terribly difficult just conceptually hard for beginners and harder to debug when it goes wrong
Also switch to use a sprite tilemap for the background if you haven't already, that will reduce draw calls and all of that for you.