引用元

Python を活用した Unreal Engine のエディタ スクリプティング | Course

アセットクラスのデータを利用する(任意の種別のアセットのみ取得する)

def getAssetClass(classType):
	EAL = unreal.EditorAssetLibrary
	assetPaths = EAL.list_assets('/Game')
	
	assets = []

	for assetPath in assetPaths:
		assetData = EAL.find_asset_data(assetPath)
		assetClass = assetData.asset_class
		if assetClass == classType:
			assets.append(assetData.get_asset())

	for asset in assets:
		print(asset)
	return assets

getAssetClass("LevelSequence")

アセットの一覧を取得して、パスを出力

import unreal

def listAssetPaths():
	EAL = unreal.EditorAssetLibrary
	assetPaths = EAL.list_assets('/Game')
	for assetPath in assetPaths:
		print(assetPath)

listAssetPaths()

選択したアセットを取得して、パスを出力

import unreal

def getSelectionContentBrowser():
	EUL = unreal.EditorUtilityLibrary
	selectedAssets = EUL.get_selected_assets()
	for selectedAsset in selectedAssets:
		print(selectedAsset)

getSelectionContentBrowser()

アクターを取得

import unreal

def getAllActors():
	EAS = unreal.EditorActorSubsystem()
	# クラスのメソッドを呼び出し「メソッドに引数が必要である」
	# というエラーが発生した場合はドキュメントで引数なしとされていた場合でも
	# EditorActorSubsystemを関数として呼び出す("()"を付ける)
	# 又は
	# EAS = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)

	actors = EAS.get_all_level_actors()
	for actor in actors:
		print(actor)

getAllActors()

選択したアクターを取得

import unreal

def getSelectedActors():
	EAS = unreal.EditorActorSubsystem()
	selectedActors = EAS.get_selected_level_actors()
	
	for selectedActor in selectedActors:
		print(selectedActor)

getSelectedActors()