How to spawn static camera c++ UE5

Hello! Try it like this

You must add these includes in the file you are working on
#include “Kismet/GameplayStatics.h”
#include “Camera/CameraActor.h”

::BeginPlay()
{
	FTransform transform(FRotator{.0f, -40.0f, .0f}, FVector{.0f, .0f, 400.0f}, FVector{1.0f, 1.0f, 1.0f});
	UWorld* poWorld = GetWorld();
	ACameraActor* MyCameraActor = poWorld->SpawnActor<ACameraActor>();
	MyCameraActor->SetActorTransform(transform);

	APlayerController* MyPlayerController = UGameplayStatics::GetPlayerController(this, 0);
	MyPlayerController->SetViewTargetWithBlend(MyCameraActor, 2.f);
}
2 Likes