Hello guys, I want someone’s input as how to make my project more efficient for mobile.
I have a track, composed in 5 lanes, each lane is divided in 26 blocks, each block has a floor, a front wall and a back wall.
So basically, the track has 5 lanes * 26 blocks per lane * 3 game objects per block to a grand total of = 390 objects, just for the track.
The reason I have divided the lanes in blocks, is so that with scaling, I can make the blocks flat (normal floor), or I can scale them up or down to grow into an obstacle or a hole. So I do need those 390 objects.
Those obstacles are generated in runtime (the scaling of the obstacles).
All those blocks are recycled, not instantiating and destroying going on. Imagine an obstacle starts is on the right side of the camera, the camera moves to the right, so the obstacle is lost to the left. On the left side there is a collider that’s a child of the camera, that triggers a function to move the block back to the right of the camera. (recycled blocks). So since it’s 5 lanes, depending on the speed, there are 5 collisions happening every second or less, and the associated code with that collision.
Is there a better way to handle this that I haven’t thought of?
The problem I’m having is that I have too many objects, too many collisions and very very occasionally (on older devices) you get small lag spikes, which take a lot off the game.
Should I have only one block collide with the camera’s collider and launch an event to tell the other blocks to move as well? would that be more efficient?