【UE×Python】レベル上のアクターを名称で取得する方法について徹底解説

Python

「unreal」(Unreal Engine Python API)は、Unreal EngineのPythonライブラリです。このAPIを使用することで、Unreal Engineをより簡単にカスタマイズすることができます。Pythonは、様々なプログラミング言語で使用される汎用的なスクリプト言語であり、「unreal」はPythonを使用して構築されています。本記事では、「unreal」を用いたレベル上のアクターを名称で取得する方法を紹介します。

# get_actor_reference関数による名称によるレベル上のアクター取得
unreal.EditorActorSubsystem().get_actor_reference(アクター名)

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

・Unreal Engine上で、どの様にPythonを使うの?
・Unreal Engine上のPythonで、どの様にレベル上のアクターを名称で取得するの?

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

get_actor_reference関数による名称を用いたレベル上のアクター取得

unreal.EditorActorSubsystem().get_actor_reference関数の基本構文

unreal.EditorActorSubsystem().get_actor_reference(
	path_to_actor: str
) 
→ unreal.Actor

unreal.EditorActorSubsystem().get_actor_reference関数の使い方

import unreal

actor_path = "PersistentLevel.StaticMeshActor_0"
actor = unreal.EditorActorSubsystem().get_actor_reference(actor_path)

### Print out "actor"
print(actor)

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

### Help of "actor"
help(actor)
LogPython: <Object '/Game/LV_Basic.LV_Basic:PersistentLevel.StaticMeshActor_0' (0x00000A23F0B99B00) Class 'StaticMeshActor'>
LogPython: __class__
LogPython: __delattr__
LogPython: __dir__
...
LogPython: tear_off
LogPython: teleport
LogPython: was_recently_rendered
LogPython: Help on StaticMeshActor object:
class StaticMeshActor(Actor)
 |  StaticMeshActor is an instance of a UStaticMesh in the world.
...
 |  Static methods inherited from _ObjectBase:
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.

まとめ

「unreal」(Unreal Engine Python API)は、Pythonを使ったUnreal Engineの開発に非常に役立ちます。この記事では、レベル上のアクターを名称で取得する方法を紹介しました。ぜひ活用してみてください。

関連検索ワード

How to get actor by name in level?

関連キーワード

unreal, python, get, actor, level, name, 取得, 名称, 名前

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