Performance testing measures how your game behaves under different conditions. You test frame rate, memory usage, and load times on target devices.
- Tests on real phones/computers (not just Editor).
- Simulates heavy gameplay (many enemies, explosions).
- Catches problems before players do.
Why Test on Real Device?
The Unity Editor runs faster than actual builds. What works in Editor may lag on phone.
| In Editor | On Real Device |
|---|---|
| Uses PC power | Uses phone CPU/GPU |
| No battery limit | Battery drains |
| No heating | Phone may overheat |
| Fast storage | Slower storage |
Note: Always test on the low-end device you support.
Target Frame Rates
Set your target based on game type. Example:
public class FPSTarget : MonoBehaviour
{
void Start()
{
// Set target frame rate
Application.targetFrameRate = 60;
// Or for mobile
Application.targetFrameRate = 30;
}
}
- Fast-paced shooter: 60 FPS (16.6 ms).
- Casual/mobile: 30 FPS (33.3 ms).
- Puzzle/strategy: 30 FPS (33.3 ms).
Test Scenario 1: Empty Scene
Establish your baseline. What to do:
- Build empty scene with just player and ground.
- Check FPS on target device.
- This is your maximum possible FPS.
If empty scene runs at 25 FPS on phone - problem with base settings (too high resolution, shadows, post-processing).
Test Scenario 2: Maximum Objects
Find your game's limit.
- Create a test scene with many enemies/bullets.
- Increase count until FPS drops below 30.
- This is your maximum spawn limit.
Example:
public class StressTest : MonoBehaviour
{
public GameObject enemyPrefab;
[ContextMenu("Spawn 100 Enemies")]
void Spawn100()
{
for (int i = 0; i < 100; i++)
{
Instantiate(enemyPrefab, Random.insideUnitSphere * 20, Quaternion.identity);
}
Debug.Log("100 enemies spawned - check FPS");
}
[ContextMenu("Spawn 500 Enemies")]
void Spawn500()
{
for (int i = 0; i < 500; i++)
{
Instantiate(enemyPrefab, Random.insideUnitSphere * 20, Quaternion.identity);
}
Debug.Log("500 enemies spawned - check FPS");
}
}
Right-click on script in Inspector - Spawn100 / Spawn500.
Test Scenario 3: Long Play Session
Some problems appear after minutes of play.
- Play for 30 minutes.
- Monitor FPS every 5 minutes.
- Watch for memory increase (leak).
Signs of problems:
- FPS slowly decreasing over time.
- Memory usage keeps growing.
- Game becomes laggy after long play.
If FPS drops over time - memory leak or objects not being destroyed.
Check memory in Profiler: Take snapshot at start, another after 10 minutes. Compare.
Common Performance Test Results
| Result | Problem | Fix |
|---|---|---|
| FPS drops with many enemies | Too many active objects | Use object pooling, reduce enemies |
| FPS drops with explosions | Too many particles | Reduce particle count/lifetime |
| FPS drops over time | Memory leak | Check for unsubscribed events |
| Low FPS on low-end device | Graphics too heavy | Lower texture size, disable shadows |