Assistance Needed for Creating Sound Cues with Imported WAV Files in Unreal Engine

Hello everyone,

I’m working on a project in Unreal Engine where I need to import WAV files and create corresponding sound cues. I’ve written a Python script to automate this process, but I’m encountering an issue.

Problem:

  1. The script successfully imports WAV files and creates sound cues.
  2. However, the sound cues are generated without being connected to the imported SoundWave assets. As a result, they are empty.

Questions:

  1. What is the proper method to connect an imported SoundWave asset to a newly created sound cue in Unreal Engine using Python?
  2. Are there any specific classes or methods that I should use to ensure that the sound cue correctly references the SoundWave?

I’m using 4.22 Version of Unreal.
Here is my codes.

import os
import re
import unreal

def normalize_filename(filename):
    normalized_name = re.sub(r'[^a-zA-Z0-9]', '_', filename)
    normalized_name = re.sub(r'_+', '_', normalized_name)
    return normalized_name

def import_wav_files_and_create_cue(wav_folder):
    asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
    wav_import_path = "/Game/Sounds/"

    for wav_file in os.listdir(wav_folder):
        if wav_file.endswith(".wav"):
            normalized_filename = normalize_filename(os.path.splitext(wav_file)[0])
            wav_path = os.path.join(wav_folder, wav_file)

            # Set up automated asset import data
            import_data = unreal.AutomatedAssetImportData()
            import_data.set_editor_property("filenames", [wav_path])
            import_data.set_editor_property("destination_path", wav_import_path)
            
            # Execute asset import
            imported_assets = asset_tools.import_assets_automated(import_data)
            if imported_assets:
                imported_asset = imported_assets[0]
                unreal.log("WAV file import completed: {}".format(imported_asset.get_full_name()))

                # Check out the WAV file from source control (may need to be done manually)
                # unreal.EditorAssetLibrary.check_out_asset(imported_asset.get_path_name())

                # Create sound cue
                create_sound_cue_from_asset(imported_asset, normalized_filename + "_Cue")

def create_sound_cue_from_asset(sound_asset, cue_name):
    # Create a new sound cue
    sound_cue_factory = unreal.SoundCueFactoryNew()
    asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
    
    # Create sound cue asset
    sound_cue = asset_tools.create_asset(cue_name, "/Game/SoundCues", unreal.SoundCue, sound_cue_factory)

    # Add SoundWave to the sound cue
    # A method for connecting SoundWave to the sound cue is needed here.

    # Save the sound cue
    unreal.EditorAssetLibrary.save_asset(sound_cue.get_path_name())
    
    unreal.log("Created Sound Cue: {} from asset: {}".format(cue_name, sound_asset.get_full_name()))

# Example usage
wav_folder = "D:/x Dropbox/k d/=== My Music ===/- MOOB/240813-MOOB-TH-SERIES/ADO/TH001 Tech House Blaze"
import_wav_files_and_create_cue(wav_folder)