Non Possesed Pawn Continues to Play Running Animation
Choose your operating system:
If you want to switch between multiple Playable Characters in your game or you have a situation where you want a Character to enter and control a Vehicle (car, plane, tank, etc.) or other Pawn that has unique controls (like a mounted machine gun a player can control), you will want to take Possession of the Character or Pawn in order to pass input information to it.
The PlayerController is what is responsible for directing a Pawn and Possession of a Pawn requires a PlayerController to be specified. Pawns themselves do not need to be a humanoid character and can be anything that you want to apply basic movement to and allow a player to control. Characters on the other hand are a form of Pawn that includes Collision and a CharacterMovementComponent by default which allows it to do basic human-like movement.
Implementation Guide
Learn how to use the Possess and UnPossess Blueprint nodes to take control of and provide input to a Pawn or Character in your project.
For the purposes of this guide we are using the Blueprint Side Scroller template, however you can use your own project if you would like. If you do not know how to create projects or use templates, refer to the Project Browser page for more information.
Steps
-
From the Content Browser, drag-and-drop into your level the additional characters you would like to control.
Here we added two additional SideScrollerCharacter Blueprints from the Content > SideScrollerBP > Blueprints folder to the level giving us a total of three characters in our level. With this particular template project, a character is already placed inside the level by default.
-
In the World Outliner, select each of the characters you want to control.
-
From the Main Toolbar, click the Blueprints button and Open Level Blueprint.
-
Right-click in the graph area, then select Create References to selected Actors option from the context menu.
This will allow us to reference each of the characters that we've selected in the level.
-
Right-click in the graph area, then search for the 1 Keyboard Event and select it.
This will allow us to fire off an event whenever the 1 key is pressed or released.
-
Add the 2 and 3 Keyboard Events to the graph.
-
Right-click in the graph and search for and add the Get Player Controller node.
The Player Controller is used to take the input from a human player and translate that into actions for a Pawn.
-
Left-click and drag off the Return Value of the Get Player Controller node and search for and add the Possess node.
This will tell the Player Controller which target Pawn to possess and take control of. When the Possess function is called, it will automatically check if a Pawn is currently controlled and UnPossess it first before attempting to Possess a new Pawn.
You can use the UnPossess function if you want to have the player release control of their Pawn and enter, say for example, a spectator type of state where they are not directly controlling a playable character.
-
Create two more Possess nodes and connect the 1, 2 and 3 Keyboard Events as shown below.
We are now set up to possess a Pawn when 1, 2 or 3 is pressed. Next we need to define which Pawn to possess from our references.
-
Connect each of the SideScrollerCharacter references to each of the In Pawn pins as shown below.
Our scripted functionality is complete and we are ready to test it.
-
Click Compile from the toolbar to update your script.
-
Click Play from the toolbar to play the game in the editor.
End Result
When you press 1, 2 or 3 on your keyboard you will switch between each of the characters in your level.
Source: https://docs.unrealengine.com/4.26/en-US/InteractiveExperiences/HowTo/PossessPawns/