Using Blueprint, I can SpawnActorFromClass
with a StaticMeshActor
, but with a Python script via the builtin Python Script plugin,
unreal.EditorLevelLibrary().spawn_actor_from_class(ue.Class(name='StaticMeshActor'), location, rot)
I got:
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')
What am I missing?
Drag off the Pressed execution pin and from the Executable actions dropdown menu search for and select the Get All Actors Of Class node. Then, click the dropdown arrow for the Actor Class and select Bp Actor to Spawn.
Unreal uses Python 3.7. 7 by default because it is an important part of the current VFX Reference Platform. The engine still supports Python 2.7, but you will need to change the version in the engine to use it.
At present (UE 4.21), Python is supported in editor, but cannot be used at runtime in a game, so you would not be able to use it as a substitute for Blueprint or runtime C++.
Figured this out by myself. Turns out that the .spawn_actor_from_class()
call does not accept ue.Class
. Instead it receives socalled ClassProperty
derived from built-in types. So the correct call should be:
unreal.EditorLevelLibrary().spawn_actor_from_class(ue.StaticMeshActor.static_class(), location, rot)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With