Clean initial commit
This commit is contained in:
61
Source/ThisWillWork/FindMyActorByName.cpp
Normal file
61
Source/ThisWillWork/FindMyActorByName.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "FindMyActorByName.h"
|
||||
#include "Engine/World.h"
|
||||
#include "Engine/Blueprint.h"
|
||||
#include "UObject/ConstructorHelpers.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
// Sets default values
|
||||
AFindMyActorByName::AFindMyActorByName()
|
||||
{
|
||||
// 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 AFindMyActorByName::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void AFindMyActorByName::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
}
|
||||
|
||||
UClass* AFindMyActorByName::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
|
||||
}
|
||||
Reference in New Issue
Block a user