How to keep camera view when swapping between PlayerController and AIController?

Hi all, I would appreciate any help you can give. I cannot figure out why this is not working.

This is what I am trying to achieve:

Seamless camera view when switching between Player Controlled and AI Controlled.

Description of gameplay: As the player, you can move around and choose an object (a tree for example) to hide behind. These are found via a trace, where the viable objects are on a specific trace channel. Once you’ve detected an object that you can hide behind, you press the Q-key which starts the hiding state. This starts by switching the characters control to the AIController, which moves the character to the location and hides, then switches back to the player controller. The whole time this is happening, the camera and spring arm should remain in the same position regardless of the controller, so that to the player, the view is seamless and remains the same.

The switch from PlayerController to AIController works, but I have been struggling to get the camera view to remain the same between the switching. I have read many forums that suggest setting the View Target, which I have done but cannot get right. I have used the function “Set View Target With Blend” from the PlayerController, setting the AI controller as the View Target, then set the “Find Camera Component When View Target” to true and unchecked “Auto Manage Active Camera Target” on the PlayerController instance during gameplay – from what I can tell this is the only way to do it? That has meant that the AI Controller switches to seeing through the characters eyes, however I cannot get it to remain looking through the characters spring arm and camera. I also tried adding a spring arm and camera to my custom AIController class, and this, when I had unchecked “Auto Manage Active Camera Target” did work but the camera was stuck where the character spawned, it did not follow the Actor and I was unable to access the camera and boom arm to set properties that would define this positioning.

I would like to add that I have programmed this in C++ originally and will be adding this functionality in C++ but switched to blueprints so that I could better understand how the Controller management works. I can share blueprints and or code if helpful?

If you are possessing with an AI controller only to move the player’s character, then that’s not needed, Player controller can also move pawns (see UAIBlueprintHelperLibrary::SimpleMoveToActor)

If that’s the case, then using that should solve your camera problem

1 Like

Hi Zeaf, thank you, I had no idea that the player controller could move pawns independent of input. I tested it earlier and it is a great alternative. Really appreciate the quick response.

I had another go at the AIController setup I described, stripped it back and coded it again, setting the bAutoManageActiveCameraTarget to False and it worked this time, so now I have both solutions to work with.

Many thanks.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.