Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delebash/398dc8c619fcf4ad3cd0116d1c00daf0 to your computer and use it in GitHub Desktop.
Save delebash/398dc8c619fcf4ad3cd0116d1c00daf0 to your computer and use it in GitHub Desktop.
UE4 C++ Spawn Actor from Blueprint
// MyClass.h ==============================
UClass *mBlueprintClass = nullptr;
// ==========================================
// MyClass.cpp ==============================
MyClass::MyClass()
{
static ConstructorHelpers::FObjectFinder<UBlueprint> blueprint_finder(TEXT("Blueprint'/Game/Path/To/Asset/MyBlueprint.MyBlueprint'")); // This path can be obtained from the editor doing right click + "Copy Reference"
if (blueprint_finder)
mBlueprintClass = (UClass*) blueprint_finder.Object->GeneratedClass;
}
void MyClass::SpawnObject()
{
const FVector spawn_point = FVector(0, 4, 7);
const FRotator spawn_rotation = FRotator();
GetWorld()->SpawnActor<AActor>(mBlueprintClass, spawn_point, spawn_rotation); // Spawn object
}
// ==========================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment