Hey guys,
In 4.12 there is new experimental feature: Blueprint Nativization.(Some of you already found it in 4.11, but it wasn’t ready to be announced).
What does the feature do?
- Generates c++ code from Blueprints
- Compiles the project with the generated code (only non-editor builds)
- Cooks the project with BlueprintGeneratedClasses replaced by newly generated native classes
The main goal of the feature is to reduce the VM overhead in runtime.
The aim of the feature (so far) is not to generate readable/friendly/reusable code.
This is an experimental beta feature. All UE4 sample games and some medium size demos were successfully nativized, but we’re still working on using the feature with the biggest projects (Paragon).
How to use the feature?
- In editor enable checkbox: Edit > Project Settings > Packaging > Nativize Blueprint Assets
- If you use UAT scripts, add “-nativizeAssets” switch in BuildCookRun command line.
What assets are converted:
- Blueprints (classes, function libraries, interfaces),
- Anim Blueprints,
- Widget Blueprints,
- User Defined Structures,
- User Defined Enums
What assets are not converted:
- Level Blueprints
- Any manually excluded Blueprints
C++ cooperation
If your project contains C++ code, make sure that all headers are properly included in your source code.
There are some rules/restrictions that help make cooperation between manually written code and the nativized code more reliable and efficient.
Do not use:
- private/protected properties with BP-Visible or Editable tags
- private/protected functions callable from BP
- noexport structures/classes
- bit-fields properties with BP-Visible or Editable tags
- private bit-fields properties
- properties of types: UBlueprintGeneratedClass, UUserDefinedStruct, UUserDefinedEnum (or any type based on them)
How to exclude blueprints from nativization?
In DefaultEditor.ini in [BlueprintNativizationSettings] sections there are:
- ExcludedBlueprintTypes (sample usage: “+ExcludedBlueprintTypes=/Script/UMGEditor.WidgetBlueprint”)
- ExcludedAssets (sample usage: “+ExcludedAssets=/Engine/Tutorial/SubEditors/TutorialAssets/Character/TutorialCharacter”)
Technical details/Misc:
- The feature should work both with VS2013 and VS2015. VS2015 is strongly recommended, especially for bigger projects. A big problem is the size of generated library. VS 2015 handles it much better. If there is a strange compiler/linker error like LNK1000, LNK1248, then try to reduce the amount of nativized Blueprints.
- The nativized code is stored in *<project>\Intermediate<platform>\NativizedAssets\Source\NativizedAssets\ *(the path was changed since 4.11)
- The BlueprintCompilerCppBackend module converts Blueprint syntax tree into C++. *Engine\Source\Developer\BlueprintCompilerCppBackend*
- The BlueprintNativeCodeGen module does a lot of magic while cooking and packaging. *Engine\Source\Developer\BlueprintNativeCodeGen*
- Assets are nativized if (and only if) they are cooked. When the cooker has no assets/maps specified (to be cooked) it cooks everything from content directory. So if you see some unused blueprints nativized, try to fill “Project Settings > Packaging > List of maps to include in a packaged build” (or MapsToCook in DefaultGame.ini).
How to debug the converted code?
If you nativize a BP-only project, then (after nativization) run GenerateProjectFiles.bat. It will add a new project to UE4 VS solution. Do not use this project to compile anything in VS. Also do not use this project to run Editor.
- To build a debug .exe file run the following lines. They can be found in log output, when nativized build is packaged (but instead of Debug there is Development switch). It’s better to copy them, so all switches are proper for your environment.
"<UE4>\Engine\Binaries\DotNET\UnrealBuildTool.exe" <project name> Win64 Debug -Project=<project path>\<project name>.uproject <project path>\<project name>.uproject -PLUGIN "<project path>\Intermediate\<platform>\NativizedAssets\NativizedAssets.uplugin" -remoteini="<project path>" -noxge -generatemanifest -NoHotReloadFromIDE -ignorejunk
"<UE4>\Engine\Binaries\DotNET\UnrealBuildTool.exe" <project name> Win64 Debug -Project=<project path>\<project name>.uproject <project path>\<project name>.uproject -PLUGIN "<project path>\Intermediate\<platform>\NativizedAssets\NativizedAssets.uplugin" -remoteini="<project path>" -noxge -NoHotReloadFromIDE -ignorejunk
- Set Working Directory in VS project (debug configuration) to *<Packaged Folder><platform><project name>\Binaries\Win64*
- Run debug in VS (do not recompile the project from VS).
Cheers!