Problem found in import settings... i'm not the sharpest tool in the shed
Performance-increase/loading-time problem [object pool]
Hello guys! :)
I'm currently working on a project, a simple game which should be playable on mobile. Since I'm a bloody beginner, my first idea was simply instantiating objects - which caused micro lags to appear. I researched, read about object-pooling and tried to create a simple one based on just the idea... without tutorials and stuff. So it's clearly not perfect.
The pool creates various tiles, which will spawn randomly depending on some factors. The problem is, that instantiating all the objects just takes way to long. The editor preview needs about 30 seconds while the mobile version will even load 1 minute.
My question is: Will it make my game/level-loading faster if i place the objects in the scene by hand and configure the pool to use those? If so, could i just let the pool create the objects and kind of "save" the state and past it in the scene? If not, are there any other ways to optimize my pool for faster loading? How should i deal with this problem?
The basic pool-creation-script:
public GameObject[] tilePrefabs;
GameObject[] tilePool;
bool[] tileIsUsed;
public int tilesOfEach; //how many tiles of each type
Vector2[] poolPosition;
Vector2[] spawnPositions;
void createTilePool() {
tilePool = new GameObject[tilePrefabs.Length * tilesOfEach];
poolPosition = new Vector2[tilePrefabs.Length * tilesOfEach];
tileIsUsed = new bool[tilePrefabs.Length * tilesOfEach];
Vector2 poolSpawn = new Vector2 (35, 45);
int tilePoolIndex = 0;
for (int i = 0; i < tilePrefabs.Length; i++) {
for (int z = 0; z < tilesOfEach; z++) {
tilePool[tilePoolIndex] = Instantiate (tilePrefabs [i], poolSpawn, Quaternion.identity);
tilePool [tilePoolIndex].GetComponent<TileMovement> ().disableMovement ();
tilePool [tilePoolIndex].GetComponent<TileMovement> ().poolIndex = tilePoolIndex;
poolPosition [tilePoolIndex] = poolSpawn;
tileIsUsed [tilePoolIndex] = false;
tilePoolIndex++;
poolSpawn.x = poolSpawn.x + 10;
}
poolSpawn.x = 35;
poolSpawn.y = poolSpawn.y - 20;
}
}
Thanks in advance! :)