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
How to Open and Close Assets
# unreal.AssetToolsHelpers
# https://api.unrealengine.com/INT/PythonAPI/class/AssetToolsHelpers.html
# unreal.AssetTools
# https://api.unrealengine.com/INT/PythonAPI/class/AssetTools.html
def openAssets():
assets = [unreal.load_asset('/Game/Textures/TX_LightSpotMove'),
unreal.load_asset('/Game/SkeletalMeshes/TutorialTPP_Mat'),
unreal.load_asset('/Game/Sounds/S_CompileSuccess')]
unreal.AssetToolsHelpers.get_asset_tools().open_editor_for_assets(assets)
// PublicDependencyModuleNames -> "UnrealEd"
#include "Editor/UnrealEd/Public/Toolkits/AssetEditorManager.h"
void UCppLib::CloseEditorForAssets(TArray<UObject*> Assets) {
FAssetEditorManager& AssetEditorManager = FAssetEditorManager::Get();
for (UObject* Asset : Assets) {
AssetEditorManager.CloseAllEditorsForAsset(Asset);
}
}
How To Save Assets
# unreal.EditorAssetLibrary
# https://api.unrealengine.com/INT/PythonAPI/class/EditorAssetLibrary.html
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
Also, if you don’t mind, you got me interrested. What kind of clean-up you are doing?
AlexQuevillon:
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
How to Open and Close Assets
# unreal.AssetToolsHelpers
# https://api.unrealengine.com/INT/PythonAPI/class/AssetToolsHelpers.html
# unreal.AssetTools
# https://api.unrealengine.com/INT/PythonAPI/class/AssetTools.html
def openAssets():
assets = [unreal.load_asset('/Game/Textures/TX_LightSpotMove'),
unreal.load_asset('/Game/SkeletalMeshes/TutorialTPP_Mat'),
unreal.load_asset('/Game/Sounds/S_CompileSuccess')]
unreal.AssetToolsHelpers.get_asset_tools().open_editor_for_assets(assets)
// PublicDependencyModuleNames -> "UnrealEd"
#include "Editor/UnrealEd/Public/Toolkits/AssetEditorManager.h"
void UCppLib::CloseEditorForAssets(TArray<UObject*> Assets) {
FAssetEditorManager& AssetEditorManager = FAssetEditorManager::Get();
for (UObject* Asset : Assets) {
AssetEditorManager.CloseAllEditorsForAsset(Asset);
}
}
How To Save Assets
# unreal.EditorAssetLibrary
# https://api.unrealengine.com/INT/PythonAPI/class/EditorAssetLibrary.html
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
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.