I’m trying to create a feature where the player can stand on top of an enemy NPC’s head and freely look around from that position.
The NPC is controlled by an AI Controller and is constantly moving randomly. I do not want to stop or interrupt the AI movement.
Here’s what I’ve tried:
-
I attached a Camera (or Spring Arm + Camera) to the NPC’s head.
-
I used Possess, Set View Target with Blend, and Set Active to switch the player’s view to that camera.
The camera view switches successfully, but I can’t rotate or look around with the mouse. The camera is fixed to the NPC’s current facing direction.
What I want is:
-
The NPC should continue moving normally under AI control.
-
The player should be able to freely rotate the camera (yaw and pitch) while the camera stays attached to the NPC’s head.
-
I don’t want to possess the NPC because I want the AI to keep controlling it.
What is the recommended way to implement this in Unreal Engine 5? Should I use a separate Camera Actor, a custom PlayerController setup, or another approach?
Use a Spectator Pawn.
Give it a camera, IMC and input to control the camera.
Spawn the class and attach it to the NPC. Posses the specator pawn.
^ We use this method as well.
Hi, thanks for your suggestion.
I tried using a Spectator Pawn, but it didn’t work as expected. When I Possess the Spectator Pawn, either the camera stops responding to mouse movement, or my player character can no longer move.
Could you show me the basic Blueprint node setup for this? A simple example or screenshot would be very helpful.
Thank you!
Dunno why spectator wouldn’t respond to mouse. I thought base class had controls baked in. Might have to edit its blueprint and add camera input like you would on character. To make player move again, you need to reposses them. Just need to save a ref to character in player controller before soul swapping to spectator. Maybe something like this in player controller blueprint:
From the input event clipped on left of screen, I branch off a bool called DroneMode (should be false by default) then call a function I made which does a sphere trace for objects (object type pawn), and if it finds one it sets the SpiedActor var. Then I check if SpiedActor is valid (just in case they were about to die). Then check if reference to my spectator actor is valid, if so I possess it and attach it to SpiedActor. If not, spawn it, save ref, then possess and attach. Finally that branch ends by setting DroneMode to true.From the first branch, if DroneMode is true, I simply set it back to false and possess my real pawn again.
Might want to use Attach Actor to Component instead of actor to actor tho so you can specify a socket to attach to. Would need to get mesh component from target actor by casting (or using an interface) tho.