Nanite Tools Missing from Window UE5.3

If someone finds this helpful, here is a python-script, that finds all Static Meshes in your open level and converts them to nanite. It recreates the behavior of the first Nanite Tools. So only Materials with opaque Material get converted. I don’t know who wrote this originally, but here is my version i had laying around:

import unreal

# get all static mesh actors
# get all materials per actor
# confirm blend mode is set to opaque or masked
# get associated static mesh
# enable nanite

def getStaticMeshActors():
    """
    Return all static meshes in level.
    """
    # classes that inherit from EditorSubsystem need to be instatiated
    actors = unreal.EditorActorSubsystem().get_all_level_actors()
    staticMeshActors = [actor for actor in actors if isinstance(actor, unreal.StaticMeshActor)]
    return staticMeshActors

def evaluateStaticMeshActors():
    """
    Get all materials for each static mesh actor and check blend modes.
    """
    for staticMeshActor in getStaticMeshActors():
        materials = staticMeshActor.static_mesh_component.get_materials()
        # confirm materials use valid blend modes
        if processMaterials(materials):
            # enable nanite
            enableNanite(staticMeshActor)

def processMaterials(materials):
    """
    Evaluate blend modes on all materials and return 1 if all are valid
    """
    validBlendModes = ['OPAQUE', 'MASKED']
    blendModes = []
    count = 0
    # iterate over materials and collect blend mode info
    for material in materials:
        if isinstance(material, unreal.Material):
            blendModes.append(material.get_editor_property('blend_mode'))
        if isinstance(material, unreal.MaterialInstanceConstant):
            parentMaterial = material.get_base_material()
            blendModes.append(parentMaterial.get_editor_property('blend_mode'))
    # check to see if valid blend mode in material blend mode
    for vbm in validBlendModes:
        for bm in blendModes:
            if vbm in str(bm):
                count += 1
    if count == len(materials):
        return 1
    return 0

def enableNanite(staticMeshActor):
    """
    Enable Nanite on static mesh associated with static mesh actor.
    """
    staticMesh = staticMeshActor.static_mesh_component.static_mesh
    if staticMesh:
        # get mesh nanite settings
        meshNaniteSettings = staticMesh.get_editor_property('nanite_settings')
        if not meshNaniteSettings.enabled:
            meshNaniteSettings.enabled = True
            # classes that inherit from EditorSubsystem need to be instatiated
            unreal.StaticMeshEditorSubsystem().set_nanite_settings(staticMesh,meshNaniteSettings, apply_changes=True)

evaluateStaticMeshActors()

PS: This does not save the Assets. So be shure to do so if you want to keep the changes.

2 Likes