Skip to content

Instantly share code, notes, and snippets.

@sephirot47
Last active May 26, 2023 18:24
Show Gist options
  • Save sephirot47/0b69609c2d15f682747a2eeb2b6c3984 to your computer and use it in GitHub Desktop.
Save sephirot47/0b69609c2d15f682747a2eeb2b6c3984 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