Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spawn actor from class in Unreal Engine using Python

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?

like image 476
kakyo Avatar asked Apr 03 '19 01:04

kakyo


People also ask

How do you spawn an actor in Unreal engine?

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.

Can you use Python for Unreal engine?

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.

Can I use Python instead of C++ in Unreal engine?

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++.


1 Answers

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)
like image 185
kakyo Avatar answered Sep 27 '22 20:09

kakyo