Make the Pawn use AI controller for a while

Ladies and Gents, I have a question for you. First, I’ll explain what I want to achieve.

So, I have an ordinary (third person template) pawn that I control in my game world. Upon approaching a pickup, the latter gets highlighted and the player can press “E” key to pick up the highlighted item. The pickup can be further away from the pawn. What I want to do is - upon pressing “E”, key make my Pawn move to the location of the pickup object, play animation (crouching and picking up the object) and then the pawn should return to a position when the “E” key was pressed.

As far as I understand, upon pressing the “E” key the AI needs to take control of my pawn, move it to a location of the pickup, play the animation, return to the initial location where “E” key was pressed, return controls of the pawn to the player. Here comes the the core of the question - “How do I delegate temporary controls of my pawn to ai controller, then return the control to the player after a certain action has been performed?”

I tried to use unpossess / possess nodes but for some reason it doesn’t work the way I imagine it. Can someone pinpoint me to a practical way to achieve my goal?

Thank you all in advance for helping me out! You’re the best!

First, yes, you can assign a new controller to a pawn, and then un-assign it and assign the old controller.

However, the simple behavior you indicated doesn’t need any AI. You can just use the SimpleMoveTo{Actor,Location} command using the player controller as the controller.
Set up a small enum for “pickupmovementstate” in your player controller, with values “idle,” “moving to,” “picking up,” and “moving back.” Set up a “return location” variable.

Now, when the user presses E, you get the current player location and stuff that into the “return location” variable.
Then you call Simple Move To Actor with the actor to pick up.
In you Tick, if you’re in the moving-to state, poll how close you are to the actor, and when close enough, set the enum to “picking up” and play your pick up motage. When the montage fires “done,” set the num to “returning” and call Simple Move To Location with the “return location.” Inside Tick, if you’re close enough to the return location in the “returning” state, set state back to idle, and now you’re done.

Make the player controller dispatch function check this state when trying to dispatch other actions, if you want to prevent other commands while this is going on. Note: It’s the player controller that knows whether it’s in this override mode or not, not each other action.

If you will have many of these “sequences,” it might make sense to make a “sequence” like this a first-class concept in your game, so you can build and attach sequences, make them interrupt lower-priority sequences, and so on. One way of doing that is to use the Gameplay Ability System, but you can also go in a different direction, perhaps using blueprints only. However, that level of engineering is only valuable if you will have a number of these – say, more than two.

1 Like

You’re a my savior. I followed your suggestion - Simply used the Simple Move To Location node and it worked. I tried to overcomplicate everything while it was so easy to achieve. Thank you so much!

1 Like