折腾一天原来是这个问题发给大家
执行方式
传参
Truncate是把小数截断成整数的节点
常用操作
获得资源
获得场景内所有actor
actors = unreal.EditorLevelLibrary.get_selected_level_actors()
创建类糊的选中资源
==Editor下的选择节点,返回选择物体数组
unreal.VRScoutingInteractor.unreal.VRScoutingInteractor()
pythonscript执行方式
import sys
sys.path.append(“E:/project/UE5/tt”)
import importlib
import kk
importlib.reload(kk)
kk.mm()
module=importlib.import_module(‘kk’)检测加载的包,可以打印路径
UE引擎内有test包,不能用test文件名。否则不会加载–真坑
总结
游戏开发 python完全可以跳过蓝图直接搞起,可以直接跟蓝图各种通信,editor类节点,可以使用editorActor方式运行,用接口方式调用。可以跟c++通信。
查找资源
查找asset
unreal.find_asset(“/Gamer/python/aa”)
读取类
unreal.load_class(“/Gamer/python/aa”)
读取物体
obj=unreal.load_object(None,name=“/Gamer/python/aa.aa”)
unreal.Actor
get_component_by_class()
from pathlib import Path
TEX=Path("W:\\")
VALID=(".png",".tif")
DEST="/Game/Testure"
def fix_name(name):
file_name_parts=name.splite("_")
last_part=file_name_parts[-1]
last_part=last_part.replace("AmbientOcclusion","O")
last_part=last_part.replace("Normal","O")
last_part=last_part.replace("Color","O")
out_part=file_name_parts[:-1]+last_part
out_name="_".join(out+parts)
return out_name
i=O
for file_path_abs in TEX.iterdir():
if file_path_abs.suffix not in VALID:
contiunt
name=file_path_abs.stem
file_name_path=name.split("_")
last_part=="Normal"
continue
file_name_start=file_name_path[0]
only_letters=[]ch for ch in file_name_start if ch.isalpha()]
tex_category="".join(only_letters)
unreal.log(tex_category)
task=unreal.AssetImportTask()
task.automated=True
task.destination_path=fix_name(name)
task.replace_existing=True
生成一个unreal的类
class tt(unreal.object):
print()
def kk():
unreal.generate_class(tt)
创建资源
# Get a class for spawning
my_class = unreal.EditorAssetLibrary.load_blueprint_class('/Game/Project/Path/To/Blueprint.Blueprint')
# Get the editor actor subsystem
actor_subsys = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
# Actually spawn the actor
spawn_location = unreal.Vector(0, 0, 0)
inst = actor_subsys.spawn_actor_from_class(my_class, spawn_location)
复制资源
全局静态函数 unreal.GameplayStatics
UNREAL架构
Subsystem
unreal._ObjectBase
EditorActorSubsystem
get_all_level_actors
unreal.World 游戏关卡
get_data_layer_manager()返回关卡管理器
get_world_settings()WorldSettings
Actor
Actor 是可以在关卡中放置或生成的 Object 的基类。 Actor 可能包含 ActorComponents 的集合.
PostRegisterAllComponents
PostActorCreated编辑器中创建 actor 或在游戏过程中创建 actor 时,会在构造之前调用它。
UActorComponent::Activate:仅当组件设置了 bAutoActivate 时,才会调用此函数。
UActorComponent::InitializeComponent:仅当组件具有 bWantsInitializeComponentSet 时,才会调用此函数。
UnrealEditorSubsystem
UUnrealEditor子系统 用于向脚本公开编辑器功能的子系统
unreal.UnrealEditorSubsystem()
get_editor_world() 返回编辑器使用的世界
EditorActorSubsystem
spawn_actor_from_object()