UE4 project optimization experience (performance, resource management, packaging, etc. optimization)

1. How to view performance indicators

The performance data of the current software can be presented on the interface by inputting commands. During the running phase of the game, you can press the keyboard ~to display the command input box.

  • command stat fps, simple output frame rate
  • command stat unit, output the time spent by game logic thread and rendering thread
  • command stat engine, output the number of triangles currently used to calculate the rendering
  • Interface Statistics, you can see the number of triangles of all resources of the project
  • Check the packaging time, you can use Rider's Log output or Log file ( 项目路径\Saved\Logs)

Introduction to stat unit command

Frame // The total time it takes to complete a frame
Game // Logical thread, time-consuming CPU processing logic
Draw // Rendering thread, time-consuming CPU processing image
GPU // Time-consuming GPU processing the current image, you can simply view it through stat gpu time-consuming
DynRes // unknown

2. The way of performance optimization

Optimize frame rate

Performance optimization mainly focuses on the number of triangle faces. On my computer (graphics card 1080), when the number of faces is less than tens of millions, the frame rate can reach 30.

There are several ways to optimize the number of triangles:

  • Model making LOD. Especially for large numbers, such as trees and small ornaments, the optimization effect of these models is particularly obvious after LOD. There are also architectural models and geographical models in the scene. Our architectural models generally have hundreds to tens of millions of faces. To make LOD, you can use the LOD generation tool that comes with UE4, which can automatically generate a model with a set percentage of faces. If the automatically generated effect is acceptable, just save it. For small objects, you can set the surface ratio to less than 1% (the specific value needs to be tested), and there is no difference when the distance is far away, and the high-precision model can be seen when the distance is close. You can use LOD Colorationthe display mode to quickly locate the model without LOD.
  • Create a culling volume (our project considers that all models need to be seen, so this method is not used. There is a brief introduction below).

In addition, the texture resolution can also be reduced to improve rendering efficiency. You can use Lightmap Densitythe display mode to judge which models have too large or too little texture resolution. Blue means the resolution is too low, red means too high, the goal is to adjust between green and orange.

render culling

Occlusion culling switch: project setting - culling - Occlusion Culling
culling distance volume: CullDistanceVolume

Optimize UE4 project startup speed

UE4 needs to build all the meshes when starting the project. The larger the model, the more time it takes, which will cause the problem of slow project startup. Since every time the designer imports a new model or modifies the model, other colleagues need to spend this time rebuilding the model.

**Optimization solution:** There is no good solution. But what we can do is to try to optimize a model once and submit it once, and avoid multiple revisions and submissions of the same model, because each submission will bring time-consuming rebuilding.

Optimize packaging speed and reduce package capacity

UE4 will pack all maps by default, including the maps of the starter pack, and packing these useless maps will bring a lot of useless resources. Therefore, the best way to increase the packing speed and reduce the packing capacity is to add the map that needs to be packed to the packing list.
**Specific operation: **ProjectSetting - Packaging - add the map that needs to be packaged tolist of maps to include in a packaged bulid

Analysis of packaging process

The time-consuming of packaging can be Rideroutput through the log or viewed in the log file ( 项目路径\Saved\Logsinside the path), where each log has an occurrence time, and the time-consuming of packaging can be calculated by simple calculation.

The packaging process will go through the following processes:

  • BUILD COMMAND STARTED, compile the project code into an executable file
  • COOK COMMAND STARTED, build resource files
  • STAGE COMMAND STARTED, temporarily store the files generated above
  • ARCHIVE COMMAND STARTED, generate the final package

The time-consuming is mainly the first two stages, the first stage is related to the code, and the second stage is related to the amount of resources. After the code is compiled once, the second time does not need to take a lot of time, it takes about 10 seconds. In the second stage of optimization, the key is to reduce the number of resource files.

Using Jenkins for Continuous Integration Delivery

An article will be added after the construction steps.

After adopting Jenkins, not only the packaging work is handed over to the server, but also the efficiency of the workflow can be improved.

Introduction to packaging command configuration: http://wangjie.rocks/2018/08/09/ue4-uat-buildcookrun-cmd/

Delete unused resources

Use the migrate method to export the map used by the project to a new content directory. This operation will export all resource files referenced by the map. Then compare the content directory of the main project with the new content directory, so that resources that are not used in the project can be found, and then deleted.

3. Packing failure handling

Code compilation failed

  • A compilation error occurred because the file name contained Chinese characters.
    **Exception details: **garbled characters appeared during the compilation process, and then soon it was prompted that the compilation failed, but the failure indicated that the problem was not located (add more information next time you encounter it).
    **Solution: **Rename the file name, and modify the settings of git, git config --global core.quotepath false(the modification of git is not sure whether it is related)

Release package failed

  • Rider usually compiles normally, but an error is reported in the packaged version, and it is also found that Rider will also report an error after recompilation

**Exception details: **Rider recompiled and reported an error, saying that the file dll could not be opened, but occasionally the compilation was successful; using UE4 to package would report a more detailed error, and found in the log file that the compilation stopped at the Cpp I wrote, and the error was reported as "ProcessResult.StdOut: d:/ue4.23/egine/xxx/PhysXIncludes.h : fatal error C1083"
**Solution: **The cause of the problem is that the cpp file imports the exception header file (when writing code, the wrong name is similar class, the rider will automatically import the header file of this class, even if the called code is deleted, the header file will not be automatically deleted, resulting in a compilation failure), just delete it.

  • XXX has an inappropriate outermost, it was probably saved with a deprecated outer

**Specific information:**LogLinker: Error: HOTRELOADED_SceneGameMode_0 has an inappropriate outermost, it was probably saved with a deprecated outer (file: /Projects/Content/Widget/W_Error.uasset)
This problem is due to the SceneGameMode used in W_Error.uasset caused by changes.

**Solution:** Delete all the SceneGameMode used in W_Error, and then recreate the SceneGameMode.

  • The path where resources are stored has been modified, resulting in many resources not being found (materials, textures, etc.)

**Solution:** Need to re-modify the resource reference. When importing resources, it is best to determine its location at the beginning, and do not modify it easily later.

other

cache path

  1. Development project: project path/project name/Saved
  2. Release version: C:\Users\your username\AppData\Local\your project name\Saved
    web page cache path: the above path/webcache

Disable VSync (Vertical Sync)

Vsync is used to solve screen tearing. When the display refresh rate cannot keep up with the FPS of 3D applications, the problem is solved by limiting the game FPS. Generally, our application cannot reach the refresh rate of the screen, so this function can be turned off.
Closing method: There is a vsync switch in the blueprint (after testing, it is off by default). Still close smooth Frame Rate.

Profiler tool analyzes logical threads

The bottleneck lies in the analysis method of the logical thread

  1. During the running of the game, enter "stat startfile" in cmd, run for a while, and then enter "stat stopfile", and the running records will be saved in the project "Saved\Profiling\UnrealStats\" directory.

  2. Go back to UE4, open Windows-DeveloperTools-SessionFrontend, click load on the Profiler interface, and load the file just saved.

to be sorted out

stat game?

Analyze the GPU
shortcut key "Ctrl+Shift+,"

reference documents

Official documentation for performance optimization: https://docs.unrealengine.com/zh-CN/Engine/Performance/index.html

Profiler usage: https://blog.csdn.net/xingyali/article/details/82217143

Profiler official documentation: https://docs.unrealengine.com/zh-CN/Engine/Performance/Profiler/index.html

Guess you like

Origin blog.csdn.net/killfunst/article/details/112556719