InstaLOD for Unreal Engine offers a comprehensive scripting interface since the release of InstaLOD for Unreal Engine 5.1. This interface allows users to implement custom workflows for optimization, shortcuts, and complex LOD chains which would involve a lot of manual labor.
The scripting interface comes with a variety of classes and functions that are used to configure and execute an operation.
The provided classes are used to configure operations and their results.
Class | Description |
---|---|
UInstaLODImposterizeSettings | Configures an Imposterize operation. |
UInstaLODMaterialMergeSettings | Configures a Material Merge operation. |
UInstaLODMeshToolKitSettings | Configures a MeshToolkit operation. |
UInstaLODOcclusionCullSettings | Configures an Occlusion Cull operation. |
UInstaLODOptimizeSettings | Configures an Optimize operation. |
UInstaLODRemeshSettings | Configures a Remesh operation. |
UInstaLODUnwrapSettings | Configures a UV Unwrap operation. |
UInstaLODResultSettings | Configures the result of an operation. |
UFlattenMaterialSettings | Configures the resulting UE FlattenMaterial. |
UInstaLODBakeOutputSettings | Configures the Bake Output of an operation. |
The Functions are used to execute an operation or to generate material settings that are preconfigured.
Function | Description |
---|---|
ImposterizeAssets | Executes an Imposterize operation. |
MaterialMergeAssets | Executes a Material Merge operation. |
OcclusionCullAssets | Executes an Occlusion Cull operation. |
UVUnwrapAssets | Executes a UV Unwrap operation. |
RemeshAssets | Executes a Remesh operation. |
OptimizeAssets | Executes an Optimize operation. |
MeshToolKitAssets | Executes a Mesh Toolkit operation. |
CreateDefaultImposterizeMaterialSettings | Creates a UInstaLODBakeOutputSettings object which is preconfigured for an Imposterize operation. |
CreateDefaultMaterialSettings | Creates a UInstaLODBakeOutputSettings object which is preconfigured for any Unreal Engine operation. |
With Unreal Engine's Editor Utilities we can create a Blueprint function that is applied to all selected assets in the Content Browser. In this example, we will create a utility that retrieves the selection, applies an InstaLOD Remesh Operation on the selection, and appends it as a LOD.
Right-click on the content browser and select in the CREATE ADVANCED ASSET
panel Editor Utilities
> Editor Utility Blueprint
.
In the spawned window select Asset Action Utility
.
This will create a Blueprint asset in the Content Browser. In our example, we name it CreateRemeshLOD
.
After double-clicking the CreateRemeshLOD
the Blueprint editor opens up and we are ready to create our logic. First, we need to create a new Function and give it a descriptive name.
After that is done we need to configure our InstaLOD Operation.
All operations are configured in a similar way:
For the Remesh operation we need to:
After this is done and everything is connected correctly we can apply the operation on the assets through the Content Browser.
Unreal Engine's Python integration allows us to leverage the provided Unreal Classes and Functions to create complex LOD chains. Please ensure that Python is enabled in the Plugin settings of Unreal Engine.
The script will take the current selection from the Content Browser and will create an optimized LOD at index 1, a remeshed LOD at index 2, and an imposterized LOD at index 3.
The script file below needs to be saved as a .py file and executed from within Unreal Engine.
"""
InstaLOD for Unreal Engine Example LOD chain generation
"""
import unreal
# Optimize
optimize_settings = unreal.InstaLODOptimizeSettings()
# Set optimization to 50%
optimize_settings.percent_triangles = 50.0
# Result will be set at LOD Index 1
LOD_index = 1
result_settings = unreal.InstaLODResultSettings()
result_settings.target_lod_index = LOD_index
result_settings.saving_option = unreal.InstaLODSavingOption.INSERT_AS_LOD
script_result = unreal.InstaLODScriptWrapper().optimize_assets(unreal.EditorUtilityLibrary.get_selected_assets(), 0, optimize_settings, result_settings)
operation_successful = script_result.success
print(f"Optimize Operation Successful: {operation_successful}")
if not operation_successful :
print("Execution failed, aborting LOD Chain generation")
exit()
# Remesh
remesh_settings = unreal.InstaLODRemeshSettings()
# Set remesh resolution to LOW
remesh_settings.remesh_resolution = unreal.InstaLODRemeshResolution.INSTA_LOD_LOW
# Result will be set at LOD Index 2
LOD_index += 1
result_settings = unreal.InstaLODResultSettings()
result_settings.target_lod_index = LOD_index
result_settings.saving_option = unreal.InstaLODSavingOption.INSERT_AS_LOD
material_settings = unreal.InstaLODScriptWrapper().create_default_material_settings()
material_settings.flatten_material_settings.texture_size = (2048, 2048)
script_result = unreal.InstaLODScriptWrapper().remesh_assets(unreal.EditorUtilityLibrary.get_selected_assets(), 0, remesh_settings, result_settings, material_settings)
operation_successful = script_result.success
print(f"Remesh Operation Successful: {operation_successful}")
if not operation_successful :
print("Execution failed, aborting LOD Chain generation")
exit()
# Imposterize
imposterize_settings = unreal.InstaLODImposterizeSettings()
# Result will be set at LOD Index 3
LOD_index += 1
result_settings = unreal.InstaLODResultSettings()
result_settings.target_lod_index = LOD_index
result_settings.saving_option = unreal.InstaLODSavingOption.INSERT_AS_LOD
material_settings = unreal.InstaLODScriptWrapper().create_default_imposterize_material_settings()
material_settings.flatten_material_settings.texture_size = (2048, 2048)
script_result = unreal.InstaLODScriptWrapper().imposterize_assets(unreal.EditorUtilityLibrary.get_selected_assets(), 0, imposterize_settings, result_settings, material_settings)
operation_successful = script_result.success
print(f"Imposterize Operation Successful: {operation_successful}")
Result of the LOD Chain creation operation.