Last active
May 26, 2023 18:24
-
-
Save sephirot47/0b69609c2d15f682747a2eeb2b6c3984 to your computer and use it in GitHub Desktop.
UE4 C++ Spawn Actor from Blueprint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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