Automating UV Channel Deletion in Unreal Engine 5.3 Using Python

12 Views Asked by At

I'm working on a Python script that deletes all but the first UV channel of selected static meshes in the Content Browser. Is there a way in the Unreal Engine Python API to query and delete the number of UV channels? Below is my code:

import unreal

selected_assets = unreal.EditorUtilityLibrary.get_selected_assets()
num_selected_assets = len(selected_assets)

for asset in selected_assets:
    if isinstance(asset, unreal.StaticMesh):
        # Trying to get the number of UV channels, but facing issues
        num_uv_channels = asset.get_editor_property('number_of_uv_channels')
        
        # Intend to delete all UV channels except the first one
        for uv_channel_index in range(num_uv_channels - 1, 0, -1):
            # Code to delete the UV channel goes here
            pass
        
        print(f"Processed {asset.get_name()} with {num_uv_channels} UV Channels, removed all but the first one.")

print(f"Completed processing {num_selected_assets} assets.")

I encountered an error stating that the property 'number_of_uv_channels' could not be found on 'StaticMesh'. I'm not sure if I'm missing something or if there's another approach to achieve this. Any advice or suggestions on how to properly query and manipulate UV channels in UE5.3 using Python would be greatly appreciated. Thank you!

LogPython: Error: num_uv_channels = asset.get_editor_property('number_of_uv_channels') LogPython: Error: Exception: StaticMesh: Failed to find property 'number_of_uv_channels' for attribute 'number_of_uv_channels' on 'StaticMesh'

0

There are 0 best solutions below