63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "FindActorByName.h"
|
|
#include "Engine/World.h"
|
|
#include "Engine/Blueprint.h"
|
|
#include "UObject/ConstructorHelpers.h"
|
|
#include "Kismet/GameplayStatics.h"
|
|
|
|
// Sets default values
|
|
AFindActorByName::AFindActorByName()
|
|
{
|
|
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
}
|
|
|
|
// Called when the game starts or when spawned
|
|
void AFindActorByName::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
}
|
|
|
|
// Called every frame
|
|
void AFindActorByName::Tick(float DeltaTime)
|
|
{
|
|
Super::Tick(DeltaTime);
|
|
|
|
}
|
|
|
|
UClass* AFindActorByName::GetBlueprintActorClassByName(const FString& BlueprintName, const FString& BlueprintPath)
|
|
{
|
|
UE_LOG(LogTemp, Warning, TEXT("GetBlueprintActorClassByName called with name: %s"), *BlueprintName);
|
|
|
|
// Construct the full path to the Blueprint
|
|
FString _BlueprintPath = FString::Printf(TEXT("%s%s.%s"), *BlueprintPath, *BlueprintName, *BlueprintName);
|
|
UE_LOG(LogTemp, Warning, TEXT("Constructed Blueprint Path: %s"), *BlueprintPath);
|
|
|
|
// Load the Blueprint object
|
|
UBlueprint* Blueprint = Cast<UBlueprint>(StaticLoadObject(UBlueprint::StaticClass(), nullptr, *_BlueprintPath));
|
|
|
|
if (Blueprint)
|
|
{
|
|
UE_LOG(LogTemp, Warning, TEXT("Blueprint found: %s"), *BlueprintName);
|
|
if (Blueprint->GeneratedClass)
|
|
{
|
|
UE_LOG(LogTemp, Warning, TEXT("GeneratedClass found for: %s"), *BlueprintName);
|
|
return Blueprint->GeneratedClass; // Return the actor class
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogTemp, Error, TEXT("GeneratedClass not found for: %s"), *BlueprintName);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogTemp, Error, TEXT("Blueprint not found at path: %s"), *BlueprintPath);
|
|
}
|
|
|
|
return nullptr; // Return nullptr if the Blueprint is not found
|
|
}
|