Hey, everyone! So, recently I’ve been diving deeper into the Python integration in Unreal Engine, and let me tell you—it’s a ride. For those of us who are new to Unreal's API (and Unreal in general), finding answers to seemingly simple questions can sometimes feel like searching for a needle in a haystack. Case in point: How do I manage folders in Sequencer?
Well, after some digging, I figured it out, and today I’m here to share that knowledge with you. Let’s break it down:
The Root of It All (Literally)
Sequencer assets have built-in methods for listing and creating root folders. These methods return something called a Sequencer Folder. Once you've got a handle on these, you can add child folders or list them. Sounds simple enough, right?
Well, there’s a little gotcha. When you're adding a child folder, the method add_child_folder
doesn’t take a string with the folder name. Nope! It wants a Sequencer Folder instance instead. So before you can organize everything neatly into subfolders, you first need to create the folder at the root level.
My Simple Method to Save the Day
Here’s a little helper method I whipped up. It will create a folder structure for you if it doesn’t already exist. Instead of passing one long string with slashes ("/") to separate folder names, you simply pass in a list of folder names, in the order you want them nested.
Here’s a sneak peek at how it works:
def _get_lvl_seq_folder( seq_asset, dir_name_list): """ :param LevelSequence seq_asset: the level sequence to edit :param [str] dir_name_list: list of folder names that make up the full destination """ chld_dirs = seq_asset.get_root_folders_in_sequence() par_dir = None for dirname in dir_name_list: found = False for sdir in chld_dirs: if sdir.get_folder_name() == dirname: found = True par_dir = sdir chld_dirs = sdir.get_child_folders() continue if found: continue # NOTE: create folders that don't exist chld_dir = [] new_dir = seq_asset.add_root_folder_to_sequence(dirname) if par_dir: par_dir.add_child_folder(new_dir) par_dir = new_dir return par_dir
Why Should You Care?
I’m pretty sure this will save someone out there hours of trial and error. If you're working with Unreal's Sequencer and are tired of manually creating folder hierarchies (or worse, clicking through the UI to organize things), this method is a game changer. Plus, it makes you feel like a wizard when everything falls neatly into place with just a few lines of code.
So give it a shot, and let me know if it helps!
Your homie,
The Pipeline Guy
(Carlos Anguiano)