# Reference blueprint camera actor in c++

**URL:** <https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538>\
**Category:** Blueprint\
**Tags:** unreal-engine, editor, UE4, question, CPP\
**Created:** [December 27, 2015, 11:21pm UTC](https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538 "2015-12-27T23:21:38Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prazon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Prazon](https://forums.unrealengine.com/u/Prazon)\
**Post date:** [December 27, 2015, 11:21pm UTC](https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538/1 "2015-12-27T23:21:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Daekesh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/daekesh/32/918652_2.png) [@Daekesh](https://forums.unrealengine.com/u/Daekesh)\
**Post date:** [December 27, 2015, 11:27pm UTC](https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538/2 "2015-12-27T23:27:02Z")

</div>

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:

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

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

---

<div class="post-metadata">

**Author:** ![Prazon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Prazon](https://forums.unrealengine.com/u/Prazon)\
**Post date:** [December 27, 2015, 11:43pm UTC](https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538/3 "2015-12-27T23:43:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Daekesh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/daekesh/32/918652_2.png) [@Daekesh](https://forums.unrealengine.com/u/Daekesh)\
**Post date:** [December 27, 2015, 11:49pm UTC](https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538/4 "2015-12-27T23:49:22Z")

</div>

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.

> **[TActorIterator::TActorIterator](https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/TActorIterator/__ctor/2/)**
>
> Constructor

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.

---

<div class="post-metadata">

**Author:** ![Prazon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Prazon](https://forums.unrealengine.com/u/Prazon)\
**Post date:** [December 27, 2015, 11:52pm UTC](https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538/5 "2015-12-27T23:52:30Z")

</div>

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();
```

---

<div class="post-metadata">

**Author:** ![Daekesh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/daekesh/32/918652_2.png) [@Daekesh](https://forums.unrealengine.com/u/Daekesh)\
**Post date:** [December 27, 2015, 11:53pm UTC](https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538/6 "2015-12-27T23:53:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Prazon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Prazon](https://forums.unrealengine.com/u/Prazon)\
**Post date:** [December 28, 2015, 12:06am UTC](https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538/7 "2015-12-28T00:06:21Z")

</div>

I’m guessing this is done wrong

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

---

<div class="post-metadata">

**Author:** ![Daekesh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/daekesh/32/918652_2.png) [@Daekesh](https://forums.unrealengine.com/u/Daekesh)\
**Post date:** [December 28, 2015, 12:07am UTC](https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538/8 "2015-12-28T00:07:52Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Prazon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Prazon](https://forums.unrealengine.com/u/Prazon)\
**Post date:** [December 28, 2015, 12:14am UTC](https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538/9 "2015-12-28T00:14:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Daekesh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/daekesh/32/918652_2.png) [@Daekesh](https://forums.unrealengine.com/u/Daekesh)\
**Post date:** [December 28, 2015, 12:30am UTC](https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538/10 "2015-12-28T00:30:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Prazon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Prazon](https://forums.unrealengine.com/u/Prazon)\
**Post date:** [December 28, 2015, 12:41am UTC](https://forums.unrealengine.com/t/reference-blueprint-camera-actor-in-c/342538/11 "2015-12-28T00:41:15Z")

</div>

How would I assign it a UPROPERTY?
