Controlling Camera and Pawn at the same time?


I have recently begun exploring UE4, going through the basics. I have previous programming experience so handling the C++ is not a big issue.

For my game i need to move a free roaming camera separately from my main pawn (strategy 3d sidescroller, turn-based. Think “Worms” style camera and possesion of pawns). My first thought was to have the camera in the main pawn, but since i want to be able to control several different pawns during gameplay, this felt like the wrong way to go.

Right now i have this:

  1. Main pawn to be controller by player.
  2. Pawn for camera
  3. Playercontroller

I have setup the playercontroller to recieve input and set the camera pawn as the possesed pawn, delegating the input to move the camera. I then have a blueprint based on my C++ main pawn to configure the parameters from within the editor. I would like to be able to control the main pawn blueprint-instance at the same time as the camera.

My thinking is that I in my playercontroller instantiate an instance of the blueprint of my main pawn and then call appropriate functions on it (without possessing it).

What would be the best way to achieve this? Am i on the right path or is there a better solution to my problem?

(I am using mainly C++ for my game logic and would like to handle this in c++, but with possibilty to adjust certain properties in Blueprint)

add the camera as a component in your pawn and move that component around

Wouldnt this mean i need to attach it to component hierarchy and thus it will follow the movement of the actor if I affect the root component (via for example movementcomponent)? How should i handle the ability to “attach” the camera to different pawns or allow the player to free roam the camera?

I would appreciate some pros and cons with each of the ideas :slight_smile:

ok then you can just have a normal Actor with a camera component and your pawn, then get a reference to the camera actor in your controller, after that to set that actor as your camera call SetViewTargetWithBlend in your PlayerController and then you can use controller key/mouse events to move it without possessing it, and yes you’ll have to call functions in camera actor directly to move it.