I’ve been trying to set up an attack for a character using the simple move to actor node in the player controller. I was hoping to play an animation upon arriving at the other actor however I cannot find a way to get when the move to actor task is completed. I did notice that this is possible using an AI controller however, I was wondering if there was a way for both the AI controller and the player controller to possess the pawn?
Only one controller can possess a pawn at any given moment.
Use the PlayerController as the “god” controller, which doesn’t actually possess your pawn/character in question. Create your custom AIController (derived) which does what you desire to actually possess the pawn/character and perform the AI tasks needed. Then from your custom PlayerController, interpret the actual player input, and send the corresponding commands to the custom AIController which controls the character in question, and the custom AIController should be driving your character and be “smart”.
So, taking the ThirdPerson template as an example:
- Make sure that your GameMode DefaultPawn is set to “SpectatorPawn”, so no actual character will be spawned and possessed by your PlayerController
- Make sure the “Auto Possess Player” property of the character on the map is set to “Disabled” from “Player 0”, so the player will not be possessed by PlayerController_0
- Make sure “Auto Possess AI” is set to “Placed in World or Spawned”
- Make sure the “AI Controller Class” is set to your custom AIController which drives the character in a smart way
- Your game logic should enforce some kind of ownership (possessing != ownership), so your PlayerController still “controls” (or owns) the character it wishes to send command to. In case of multiple characters are “owned” by one controller, you might also want to enforce the concept of what are the “currently” active characters to receive PlayerController commands. Enforce the binding, so the PlayerController maintains a list of owned characters, and currently active characters, so PlayerController knows who to send commands to
- Sending commands basically means invoking the currently owned and active characters’ respective custom AIControllers’ events/functions - things like move to destination, or "forward key is pressed, keep moving forward)
- Once the character reaches the destination, its AI controller’s associated behavior tree will be able to play your pretty looking animation.
Pretty clever! Nice…
Did this work for you, teak421? I was wondering this same exact thing and confirmation would be awesome.
EDIT: Nevermind, I tried it out once I got home and it works great. Clever solution, indeed!
This is a nice solution and glad to hear others have gotten it working.
Sadly I’m stuck at step 6
My Player Controller has a SpawnCharacter method which gets the Game Mode, casts it to my Game Mode and then tells calls a method in that to spawn my character.
A reference to the spawned actor is returned to my player control and added to an array of pawn references.
At some point I select one of the pawns in the array, cast it to my character class and get the AIController.
At this point the controller seems to be ‘none’.
I believe I followed your steps configuring the settings until this point.
I’m sorry, this is pretty vague but I’m not sure what other info I could give.
^^^ I think I had this same issue. In order to get this to work I had to spawn the default controller of the character.
What I can’t figure out is: why does the camera stop following the character when it is possessed by an AI Controller?
mabdog did you manage to figure out why does the camera stop following the character when it is possessed by an AI Controller?
I have been trying to find it for a while now and still nothing…
I have the same issue, camera stop reacting to input… please share if you get any findings