使用蓝图,我可以SpawnActorFromClass
StaticMeshActor
,但可以通过内置的Python脚本插件
unreal.EditorLevelLibrary().spawn_actor_from_class(ue.Class(name='StaticMeshActor'), location, rot)
我知道了
LogPython: Error: TypeError: EditorLevelLibrary: Failed to convert parameter 'actor_class' when calling function 'EditorLevelLibrary.SpawnActorFromClass' on 'Default__EditorLevelLibrary'
LogPython: Error: TypeError: NativizeProperty: Cannot nativize 'Class' as 'ActorClass' (ClassProperty)
LogPython: Error: TypeError: NativizeClass: Cannot nativize 'Class' as 'Class' (allowed Class type: 'Actor')
我想念什么?
答案 0 :(得分:1)
我自己弄清楚了。原来.spawn_actor_from_class()
呼叫不接受ue.Class
。相反,它接收从内置类型派生的所谓的ClassProperty
。因此正确的呼叫应该是:
unreal.EditorLevelLibrary().spawn_actor_from_class(ue.StaticMeshActor.static_class(), location, rot)
答案 1 :(得分:0)
我不确定您是否正在使用20tab之前的Python插件,但是您可以通过in编辑器控制台甚至在运行时使用以下代码示例轻松地完成此操作
def spawn(cls):
ue.editor_deselect_actors()
obj = ue.get_editor_world().actor_spawn(cls)
ue.editor_select_actor(obj)
return obj
__builtins__['spawn'] = spawn # so it's always available in the Py console
该插件可从https://github.com/20tab/UnrealEnginePython免费获得,目前在4.22版之前一直支持