Python to Open / Save assets using Editor

Hey all,

I noticed the unreal.AssetTools has an open_editor_for_assets, but I’m unsure of how to force a save through the editor for those open assets (I generally run some object clean-up logic in my editors during asset save). Has anyone come across this?

Good morning!

I have some videos that might help with this.
Sadly, I had to use a little bit of C++ to close the assets and get the opened assets list, but the saving part is all in Python :slight_smile:

How to Open and Close Assets

# unreal.AssetToolsHelpers
# unreal.AssetTools
def openAssets():
    assets = [unreal.load_asset('/Game/Textures/TX_LightSpotMove'),

// PublicDependencyModuleNames -> "UnrealEd"
#include "Editor/UnrealEd/Public/Toolkits/AssetEditorManager.h"
void UCppLib::CloseEditorForAssets(TArray<UObject*> Assets) {
    FAssetEditorManager& AssetEditorManager = FAssetEditorManager::Get();
    for (UObject* Asset : Assets) {

How To Save Assets

# unreal.EditorAssetLibrary
def saveAsset():
    unreal.EditorAssetLibrary.save_asset('/Game/Textures/TX_LightSpotMove', only_if_is_dirty=False)

Let me know if it is what you are looking for :slight_smile:
Also, if you don’t mind, you got me interrested. What kind of clean-up you are doing?

Thanks Alex, I’ll give that a try.

I have some editor only fields that I then read and optimize to a more performant runtime bitfield / whatever implementation on Save. Just simple stuff like that.