Forked from sephirot47/UE4 C++ Spawn Actor from Blueprint .cpp
Created
March 3, 2022 04:05
-
-
Save delebash/398dc8c619fcf4ad3cd0116d1c00daf0 to your computer and use it in GitHub Desktop.
UE4 C++ Spawn Actor from Blueprint
This file contains hidden or 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