Change Prefab script field values when object is not instantiated

Hello All.

Building a space shooter. Once all enemies are all destroyed in a “sector”, I go to a new scene(new sector) with new back ground and music. I want to be able to change field values in the object script for the enemy as a “level up” to increase difficulty level in next sector; example is fire power or increased movement speed.

I’m currently instantiating enemies as they spawn and destroying when health is at zero. The instantiation is using a scriptable object for most of the initial fields.

My initial thought is to “pool” enemies at runtime as I think I can modify the fields on “inactive” objects. Is this a correct method or is there a better way?

Pooling should work, or any means of gathering your gameobjects such as a List. This way, you can iterate through them and apply their new stat values as you move to the next level. And this would be more efficient.

You can also just apply the stat modifying values right after instantiation.

GameObject newEnemy = Instantiate(enemyPrefab);
EnemyStats enemyStats = newEnemy.GetComponent<EnemyStats>();
enemyStats.AttackPowerIncrease(int currentLevel);