Automation: Nanite Blotch Removal
The assets covered in dark 'shadows' that aren't true shadows and tend to look like a sub-mesh penetrating the visible mesh. I don't know the formal explanation, but it's easy to fix and move on (unless you have a ton of assets). Example below, with enabled collision:
Fixed mesh below.
The fix is to change Fallback Target from Auto to Relative Error (with a value of 0.0) Plus, in testing I found that it seems to be good to have Max Edge Length Factor set to 1.0 (but feel free to check that is making any difference).
William Faucher has a nice video on solving this problem manually. https://youtu.be/F3XSKXhIAuU?si=Co4xnwGnz1oecZja So the point of this post is that I thought it would be good to see if all that can be automated to a widget utility button, using Execute Python Script.
Ideally, you should be able to batch process a selection of assets without even opening the mesh editor. Running the script with a folder of static mesh assets selected in the content browser works, but can take a good while to parse each one (still way faster than doing the steps required manually).
The python is given below. Best to have a read of it , but it doesn't need any special adjustments. It can be called via its path in the Command line of unreal in Python mode, or it can be called from a utility widget.
Expand Python
import unreal
def enable_nanite_and_apply_settings():
# Get the selected assets in the Content Browser
selected_assets = unreal.EditorUtilityLibrary.get_selected_assets()
if not selected_assets:
unreal.log_warning("No assets selected in the Content Browser.")
return
for asset in selected_assets:
if isinstance(asset, unreal.StaticMesh):
static_mesh = asset
try:
# Use get_editor_property to access Nanite-related properties
nanite_settings = static_mesh.get_editor_property("nanite_settings")
if not nanite_settings:
unreal.log_warning(f"Asset '{static_mesh.get_name()}' does not have accessible Nanite settings.")
continue
# Enable Nanite support
if not nanite_settings.get_editor_property("enabled"):
nanite_settings.set_editor_property("enabled", True)
unreal.log(f"Enabled Nanite for '{static_mesh.get_name()}'.")
# Set fallback target to Relative Error
if nanite_settings.get_editor_property("fallback_target") != unreal.NaniteFallbackTarget.RELATIVE_ERROR:
nanite_settings.set_editor_property("fallback_target", unreal.NaniteFallbackTarget.RELATIVE_ERROR)
unreal.log(f"Set Fallback Target to 'Relative Error' for '{static_mesh.get_name()}'.")
# Set fallback relative error to 0.0
if nanite_settings.get_editor_property("fallback_relative_error") != 0.0:
nanite_settings.set_editor_property("fallback_relative_error", 0.0)
unreal.log(f"Set Fallback Relative Error to 0.0 for '{static_mesh.get_name()}'.")
# Set MaxEdgeLengthFactor to 1.0
if nanite_settings.get_editor_property("max_edge_length_factor") != 1.0:
nanite_settings.set_editor_property("max_edge_length_factor", 1.0)
unreal.log(f"Set MaxEdgeLengthFactor to 1.0 for '{static_mesh.get_name()}'.")
# Save the asset to ensure changes are applied
if unreal.EditorAssetLibrary.save_asset(static_mesh.get_path_name()):
unreal.log(f"Applied changes and saved '{static_mesh.get_name()}'.")
else:
unreal.log_warning(f"Failed to save changes for '{static_mesh.get_name()}'.")
except Exception as e:
# Log the error and continue
unreal.log_error(f"Failed to modify '{static_mesh.get_name()}': {e}")
else:
unreal.log_warning(f"Selected asset '{asset.get_name()}' is not a Static Mesh.")
# Run the script
enable_nanite_and_apply_settings()
Finishing up with a daft question -- why hasn't there been an internal fix for this from Epic during the past few years?
Yorumlar