Profiling is a critical step in optimizing game performance in Unreal Engine. One way to monitor specific areas of your code is to use stat startfile
and stat stopfile
commands. These commands help capture profiling data for in-depth analysis, enabling you to identify and fix performance bottlenecks.
Overview
stat startfile
and stat stopfile
are console commands that generate a profiling data file (.ue4stats) for Unreal Engine’s built-in Unreal Insights tool. You can use them to focus on certain sections of your gameplay or visualize the overall performance over time.
Getting Started with Profiling
Step 1: Launching Your Project
- Open your project in Unreal Engine.
- Start playing your game either in the editor (PIE) or by launching a standalone game.
Step 2: Running the Commands
- Press the
~
key (or your project’s console key) to bring up the console command line. - Enter
stat startfile
to begin recording profiling data. - Play your game normally while the profiling data is being recorded.
- Enter
stat stopfile
when you’re ready to stop profiling.
This generates a .ue4stats file and stores it in the project’s Saved/Profiling/UnrealStats
folder.
Step 3: Analyzing the Data with the Session Frontend
Once you have recorded profiling data using stat startfile
and stat stopfile
, you can use Unreal Engine’s Session Frontend to analyze the results.
Open Session Frontend:
- In the Unreal Engine editor, open the Session Frontend via “Tools” > “Session Frontend.”
Access Profiler Tab:
- In the Session Frontend, switch to the “Profiler” tab. This tab allows you to open profiling files for analysis.
Load Profiling Data:
- Click the “Load” button in the toolbar to browse for the profiling data you generated in Step 2 (located in the
Saved/Profiling/UnrealStats
folder). - Select the appropriate .ue4stats file and click “Open.”
- Click the “Load” button in the toolbar to browse for the profiling data you generated in Step 2 (located in the
Examine the Data:
- Frame Graphs: Analyze the graph to see frame times and breakdowns for each frame. You can see spikes indicating where the frame rate drops.
- CPU Usage: Check how much processing time each game thread uses. This helps identify the heaviest threads that may need optimization.
- GPU Usage: Understand GPU frame times to identify graphics-related bottlenecks.
- Memory Usage: See how much memory the game uses over time, which can reveal memory leaks or high usage scenarios.
Inspect Specific Time Ranges:
- Click and drag on the graphs to zoom in on specific time ranges. This feature lets you focus on particular moments that had performance issues.
Compare Multiple Sessions:
- You can load multiple profiling sessions in the Profiler to compare how different changes impact performance.
By following these steps and using the Session Frontend effectively, you can gain valuable insights into the performance characteristics of your Unreal Engine project, enabling you to target specific areas for optimization.