1.插件导入
- pyhton editor
-
sequencer scripting
2.python import脚本问题
在设置里加入新的文件夹当做引用文件夹,同时重启编辑器
这样就能在代码里import这个文件夹的其他文件了
3.API
官网API:没有这个寸步难行
https://docs.unrealengine.com/4.26/en-US/PythonAPI/
4.使用案例
- editor执行 在cmd内键入
py test.py绝对路径
就可以执行python了
- 场景相关
获取场景选择的物体
actors = unreal.EditorLevelLibrary.get_selected_level_actors()
创建一个actor
position = unreal.Vector(0,0,0)
rotation = unreal.Quat(0,0,0,1)
cube = unreal.EditorLevelLibrary.spawn_actor_from_class(unreal.StaticMeshActor,position,rotation.rotator())
检测射线碰撞
position = unreal.Vector(0,0,0)
end_position = unreal.Vector(1000,0,0)
actors_ignore = []
hit = unreal.SystemLibrary().line_trace_single(unreal.EditorLevelLibrary().get_editor_world(),position,end_position,unreal.TraceTypeQuery.TRACE_TYPE_QUERY1,True,actors_ignore,unreal.DrawDebugTrace.NONE,True) # PERSISTENT
- 资源常用类
unreal.EditorAssetLibrary
unreal.AssetToolsHelpers.get_asset_tools()
例如加载某些资源
mesh = unreal.EditorAssetLibrary.load_asset('/Engine/BasicShapes/Cube.Cube')
material = unreal.EditorAssetLibrary.load_asset('/Engine/BasicShapes/BasicShapeMaterial.BasicShapeMaterial')