Switching Camera Actors

Hey Community,

Oh boy it’s been a while since i’ve had to post a question but nevertheless something has stumped me. For the last few hours i’ve been google searching and experimenting around but I can’t seem to figure it out.

Basically all I want to do is when I press a button or even enter the world I would like to switch my camera to a camera in the scene already.

What do I have for code?

void ARPGCharacter2::BeginPlay()
{
	for (TActorIterator<ACameraActor> ActorItr(()); ActorItr; ++ActorItr)
	{
		if (ActorItr->GetName() == "CameraActor_2")
		{
                  // I am using this to find the actor in the scene
		}
	}
}

I’m using the character class and i’ve actually already figured out a crude version of doing this with a camera already attached to the Root but I would much rather make use of placing actors down and being able to call them on command.

Something i’ve figured out already with the google searching however is that I should be using SetViewTarget but admittedly I can’t seem to figure out that approach either. I was looking at Set Main Camera View - Cinematics & Media - Epic Developer Community Forums but the code proposed came up with an error in it.

Anyways, thanks a bunch.

Each PlayerController which each player have have it’s on ViewTarget, which is actor that you can set, since each actor have function called CalcCamera()

Which sets camera position for actor, so each actor has it’s own camera setup, as you see in code snippit by default it’s search for UCameraComponent in you actor and set camera to it’s position, but you can override it to change behavior of camera for actor

You wouldn’t happen to have a better example would you? What exactly is FMinimalViewInfo& OutResult and what data goes there? How is it sent exactly or better yet how can I grab the default data that’s already there in the camera that I placed in the scene already?

That documentation doesn’t really make all that much sense to me.

Well click it and you will know

It’s a struct containing camera data. Now CalcTarget is called on every frame to check camera postion, it passing refrence (thats why it has &) of FMinimalViewInfo , not pointer but ready variable somewhere in memory which you can set, when you change it you change that variable which later is gonna used in rendering. So for example if you do this:

void ASomeActor::CalcCamera(float DeltaTime, FMinimalViewInfo& OutResult) {

         OutResult.Location = FVector(0,0,500);

}

Will position camera permanently in 0,0,500 postion when you set ASomeActor object as view target. So as you can see you have full freedom here what you can do with camera.

You can also explore APlayerCameraManager which contains more advance camera stuff, you can access it from PlayerController, each controller has instance of it, also SetViewTarget in Player Controller is just forwarding of function in that class

But if you want you can just use CameraComponent and CameraActor is just empty actor with CameraComponent which you can set as ViewTarget and move it as you like, but if you want somethign attached to character just place camera component inside him

I think you’ve missed my question entirely or you’re just all over the place or maybe I am after being so frustrated with this. I have a CameraActor inside the world. Literally placed in the editor somewhere. I know the name of said CameraActor because of the Iterator I had used.

What I want to do is as soon as I spawn in world I want to use that Camera as my main camera. That’s all.

How do I do that? Look at my code and tell me what you need or tell me what I need so I can get this done.

Thing is I am using your method right now and the problem is I don’t want to have to set these up manually every single time. I’d prefer to be able to just plop a camera down and then reference it.

Although thank you. If I have to do it all manually then that’s going to suck but at the very least it works. So thanks. :slight_smile:

I’d still like an answer to what I am looking for though.

call SetViewTarget(CameraActor) in PlayerController that belong to player that yo want to change camera

Thanks a bunch.