Reference blueprint camera actor in c++

FVector Forward = PlayerCharacter->GetActorForwardVector();
FVector Offset = (InLocation - PlayerCharacter->GetActorLocation()).GetSafeNormal();

I’m trying to change the PlayerCharacter to my camera actor in my game but it’s a blueprint actor. Is there anyway to reference it properly in c++ for this? I tried

UBlueprint* blueprint = BlueprintObj(TEXT("Blueprint'/Game/WolfPackBattalion/Blueprints/CameraZoom.CameraZoom'"));

But it doesn’t seem to work

  1. Never, ever, import blueprints into c++. You want the Blueprint Generated Class. A very important vital distinction. Blueprints do not get cooked and are not usable in a package game. Blueprint Generated Classes are.

  2. Use the folloiwng code:

    static ConstructorHelpers::FObjectFinder cameraClassFinder( TEXT(“Blueprint’/Game/WolfPackBattalion/Blueprints/CameraZoom.CameraZoom_C’”) );

Note the _C. You can access the BGC with cameraClassFinder.Object

Edit (x50): Apparently, I can’t copy+paste code without breaking everything.

Thanks! But can I use this to get a forwardvector and a safenormal?

What if I use getallactors of class?

TArray<AActor*> OutActors;
 UGameplayStatics::GetAllActorsOfClass(this, MyActorClass::StaticClass(), OutActors);
 
 // e.g. get location of first actor
 OutActors[0]->GetActorLocation();

I’m guessing this is done wrong

UGameplayStatics::GetAllActorsOfClass(this, CameraZoom::BlueprintClass(), OutActors);

What I wrote will import a class, not an instance of a class. You won’t be able to get anything like location or anything. What you can do is use the TActorIterator to search the level for your camera object.

Then compare the found actor’s classes to your BP class.

You’ll need to load the blueprint class in the constructor of your c++ class and store a reference.

That’d work. Use the blueprint class instead of MyActorClass::StaticClass()

static ConstructorHelpers::FObjectFinder cameraClassFinder( TEXT(“Blueprint’/Game/WolfPackBattalion/Blueprints/CameraZoom.CameraZoom_C’”) );

Note the _C. You can access the BGC with cameraClassFinder.Object

static ConstructorHelpers::FObjectFinder cameraClassFinder(TEXT(“Blueprint’/Game/WolfPackBattalion/Blueprints/CameraZoom.CameraZoom_C’”));
TArray<AActor*> OutActors;
UGameplayStatics::GetAllActorsOfClass(this, cameraClassFinder::BlueprintClass(), OutActors);

This isn’t working, I’ve tried

	static ConstructorHelpers::FObjectFinder cameraClassFinder(TEXT("Blueprint'/Game/WolfPackBattalion/Blueprints/CameraZoom.CameraZoom_C'"));
	TArray<AActor*> OutActors;
	UGameplayStatics::GetAllActorsOfClass(this, cameraClassFinder.Object::BlueprintClass(), OutActors);

I’ve also tried

	static ConstructorHelpers::FObjectFinder cameraClassFinder(TEXT("Blueprint'/Game/WolfPackBattalion/Blueprints/CameraZoom.CameraZoom_C'"));
	TArray<AActor*> OutActors;
	UGameplayStatics::GetAllActorsOfClass(this, cameraClassFinder.Object, OutActors);

I’m guessing it’s something easy I’m missing

Somehow my copy/paste failed. Not my day for that. Probably something to do with html stripping…

static ConstructorHelpers::FObjectFinder<UClass> cameraClassFinder( TEXT( "Blueprint'/Game/WolfPackBattalion/Blueprints/CameraZoom.CameraZoom_C'" ) );

You need to do this in the consrtuctor and assign the .Object to a UPROPERTY in the class. Then use that UPROPERTY in your get all actors of class.

How would I assign it a UPROPERTY?