LoginSignup
7
8

More than 3 years have passed since last update.

Unreal Engine4 で公式Pythonを使うまで

Last updated at Posted at 2019-07-09

Unreal Engine4 で公式Pythonを使うまで

環境

  • Windows 10
  • Unreal Engine version 4.22

プラグインの有効化

edit_plugin.PNG

  • Python Editor Script Plugin
    plugin.PNG

  • Editor Scripting Utilities
    ESU.PNG"

このプラグインが入っていないと、よく使うEditorAssetLibrary、EditorFilterLibrary、EditorLevelLibrary、およびEditorStaticMeshLibraryが使えない。プラグインのインストール・有効化が必要

プラグインを有効化したあとは必ず、UEを再起動する

スクリプトの実行結果を表示・実行するためにアウトプットタブを開きます

output.PNG

サンプルをダウンロード

フォルダをリネーム

  • 環境によるのかもしれませんが、フォルダ名に空白が入ると実行されなかったので『Basic Examples』と『Unreal Studio Examples』の空白を削ります。『BasicExamples』『UnrealStudioExamples』にリネームします。階層も深かったので、C:\epic\PythonExamples\BasicExamplesでアクセスできるようにしました

Pythonのコードを実行します

  • ファイルを指定して実行

hello.PNG

  • 直接コードを実行

pythoncode.PNG

公式サンプル一覧

ファイル名 内容
hello_world.py 最も基本なhello_worldをコンソールに表示します。
unreal_hello_world.py hello_world.pyと全く同じ結果となります。最も基本なhello_worldをコンソールに表示しますが、unrealの関数で出力します。
edit_property.py プロパティの編集サンプルです。サンプルとしてメディアプレイヤーのプロパティを変更します。
pyside_simpleexample.py PySideを使用してWindowを表示するサンプルです。事前にpip instalk Pysideをしておかないと動作しません。pip installの方法は後述
scoped_editor_transaction.py スコープトランザクションのサンプル、スコープを使ってまとめてプロパティを変更するサンプルです
unreal_object.py unrealのobjectを作るサンプルです。vectorオブジェクトのサンプルです。vector.pyと同じです。
vector.py vectorオブジェクトのサンプルです。unreal_object.pyと同じです。
  • Unreal Studio Examples
ファイル名 内容
ContentBrowser\content_browser.py
ConvertActors\convert_actors.py
DatasmithImport\import_datasmith.py
JoinActors\join_actors.py
LevelEditing\level_editing.py
MergeActors\merge_actors.py
ReplaceMaterials\replace_red_materials.py

pip install

pipの場所
windows10の場合、pip installを直接打つと『pip fatal error in launcher』エラーが出て動作しないので、python -m 経由で実行する。targetの設定も忘れずに

  • C:\Program Files\Epic Games\UE_4.21\Engine\Source\ThirdParty\Python\Win64\Scripts
cd C:\Program Files\Epic Games\UE_4.21\Engine\Source\ThirdParty\Python\Win64\Scripts
python -m pip install --target="C:\Program Files\Epic Games\UE_4.21\Engine\Source\ThirdParty\Python\Win64\Lib\site-packages" Pyside

Pythonの場所

UnrealEngineにbuilt-inらしい...。

import os
print(os.getcwd())
LogPython: C:\Program Files\Epic Games\UE_4.22\Engine\Binaries\Win64
import sys
print(sys.executable)
LogPython: C:\Program Files\Epic Games\UE_4.22\Engine\Binaries\Win64\UE4Editor.exe

参考

7
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8