AI controlled player character

Hello,
Was wondering if any one had a good approach to having your player character be controlled by AI while having a top down camera on them for a AFK or idle style rpg. I know what AI blueprint i want to run but i cant make it work with controller or camera.

First, you need to make sure that all your “input actions” are handled by a PlayerController, not by a Character.
The PlayerController then needs to control the Character using some interface you define. (Or maybe just the CharacterMovementComponent interface if you’re going that route.)
Finally, you can then develop an AIController.
To make the character be controlled by the AIController, you then need to unpossess the character from the playercontroller, and instead make it be possessed by the AIController.

If you want camera to still follow the character around, you can make the playercontroller use SetViewTarget to use whatever camera is attached to the character, or you can implement/subclass the PlayerCameraManager.

Hmmm, didn’t even think of that, I’ll have to give it a try. TY! i will let you know if it works




Make sure auto posses is disabled and character has “AI controller class” set to your AI controller you make
image
and your default pawn class set to none

Correct.
To clarify, create custom events your AI and player can call.

Hi, I have about the same problem in my game. By following the advice given here I managed to make my player character possessed by an AI controller when the player is afk for a while and when he is not afk anymore, that is when the player moves the mouse or presses a key on the keyboard, the player regains possession of the player character.
However I would like the position and rotation to be the same, currently my AI controller moves the player character along a spline but when I regain possession I return to the initial position where my player character was before being afk, I don’t know if I’m very clear.

When you say “player” I assume you mean “player Pawn” (or Character, which is a subclass of Pawn.)
I mention this, because when the Unreal Engine talks about Player, it really talks about the Player Controller, which may or may not possess a pawn.

You’re currently saying that, when your player controller possesses a pawn, it teleports that pawn to the location of the controller? That doesn’t ring a bell, because typically the player controller will just hang out at the origin, and the player camera will be derived by the currently possessed pawn, and the pawn will move freely.

So, if all you do is “unpossess” the pawn of the player controller, then “possess” with the AI controller, and, later, “unpossess” the AI controller and “possess” it again with the player controller, that should “just work,” unless you’re doing something special in the controller to make it not work, like storing a controller location or trying to attach the pawn to the controller or something.