【UE×Python】コンテンツ内のアセットを読み込む方法およびオブジェクトデータを表示する方法について徹底解説(SM_Chair)

Python

「unreal」(Unreal Engine Python API)は、Unreal EngineのPythonライブラリです。このAPIを使用することで、Unreal Engineをより簡単にカスタマイズすることができます。Pythonは、様々なプログラミング言語で使用される汎用的なスクリプト言語であり、「unreal」はPythonを使用して構築されています。本記事では、「unreal」を用いたコンテンツ内のアセットを読み込む方法およびオブジェクトデータを表示する方法を紹介します。

# load_asset関数によるコンテンツ内のアセットの読み込み
unreal.load_asset(アセットのパス)

下記の様な内容で悩んでいる/困っている場合に使える方法を参考までにご共有させて頂きます。

・Unreal Engine上で、どの様にPythonを使うの?
・Unreal Engine上のPythonで、どの様にコンテンツ内のアセットの読み込むの?また、どの様にオブジェクトデータの表示するの?

また、「unreal」を使用する上で基礎的な情報は下記の記事で紹介しております。
他の「unreal」のクラスや関数について気になる方はこちらの記事をご覧ください。

unreal.load_asset関数によるコンテンツ内のアセットの読み込み/print関数によるデータの表示

unreal.load_asset関数の基本構文

unreal.load_asset(
	name: str, 
	type: Union[Class, type] = Object.static_class(), 
	follow_redirectors: bool = True
) 
→ Any

unreal.load_asset関数の使い方

import unreal

chair_asset = unreal.load_asset('/Game/StarterContent/Props/SM_Chair.SM_Chair')

### Attribute of "chair_asset"
for attribute in dir(chair_asset): print(attribute)

### Help of "chair_asset"
help(chair_asset)

### Information of "chair_asset"
print(chair_asset.get_class())
print(chair_asset.get_fname())
print(chair_asset.get_path_name())
LogPython: __class__
LogPython: __delattr__
LogPython: __dir__
...
LogPython: set_num_source_models
LogPython: static_class
LogPython: static_materials
LogPython: Help on StaticMesh object:
class StaticMesh(StreamableRenderAsset)
 |  A StaticMesh is a piece of geometry that consists of a static set of polygons.
 |  Static Meshes can be translated, rotated, and scaled, but they cannot have their vertices animated in any way. As such, they are more efficient
 |  to render than other types of geometry such as USkeletalMesh, and they are often the basic building block of levels created in the engine.
 |  see: https://docs.unrealengine.com/latest/INT/Engine/Content/Types/StaticMeshes/
 |  see: AStaticMeshActor, UStaticMeshComponent
...
 |  Static methods inherited from _ObjectBase:
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
LogPython: <Object '/Script/Engine.StaticMesh' (0x00000B0A93F40300) Class 'Class'>
LogPython: SM_Chair
LogPython: /Game/StarterContent/Props/SM_Chair.SM_Chair

まとめ

「unreal」(Unreal Engine Python API)は、Pythonを使ったUnreal Engineの開発に非常に役立ちます。この記事では、コンテンツ内のアセットを読み込む方法およびオブジェクトデータを表示する方法を紹介しました。ぜひ活用してみてください。

関連検索ワード

How to read asset in content browser?
How to show data of object?

関連キーワード

unreal, python, read, show, 読み込み, 表示

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny