SwitcherPawnComponent for switching between pawns
The SwitcherPawnComponent
is a custom component created to facilitate the dynamic change of possession between pawns in a scene. This component integrates with the PlayerController
to efficiently locate and switch control to specific pawns based on their unique identifiers using GameplayTags
.
This component solves the problem of handling multiple pawns in a level and the need to change possession between them dynamically, using a centralized and extensible logic. It is particularly useful when in the level there are several view changes with Pawn types of different behaviors, as for example, the change between the orbital view and the first person, where there is a change of camera and also a change in the Pawn and its behavior.
Integration with IdealTwin PlayerControllers
At IdealTwinthe PlayerControllers
created for the project already have an integrated base of SwitcherPawnComponent
facilitating its use at any level of the game. In addition, at the beginning of the outdoor and indoor levels, they use this logic of change of possession from the start, automatically performing the first possession to the corresponding pawn.
Therefore, it is recommended to use this component also to establish the order of possession if you wish to modify it.

Operation
The SwitcherPawnComponent
uses the following main concepts:
PlayerController: The component is designed to reside in the
PlayerController
which is in charge of making the transitions.Interface: PawnSwitchInterface: To identify the pawns that can be owned, the SwitcherPawnComponent uses an interface called PawnSwitchInterface. All class actors
Pawn
that implement this interface will be considered candidates for change of ownership. The interface includes a key method that returns theGameplayTag
associated with the pawn. This tag is used to determine which pawn should be owned.GameplayTags: Each pawn implements a
GameplayTag
tag, which acts as an identifier. This tag is queried by the component to ensure that the possession changes to the correct pawn.
Configuration for using the SwitchComponent
The design of the SwitcherPawnComponent allows for easy customization and extension:
Add Pawns with Tags:
It is only necessary to implement the interface PawnSwitchInterface in the pawns and assign them a Gameplay Tag adequate.Flexible Interface:
The interface can be extended to include more information if the change of possession flow needs additional logic.Integration with Gameplay Tags:
By taking advantage of the Gameplay TagsThe component integrates seamlessly with other engine systems, such as skills, inventories or contextual behaviors.
Add New Tags
Only one Pawn is allowed per tag. The system uses an internal list where it stores the unique pawn references for each of the GameplayTag in the same level, in case there are 2, the last one registered will be overwritten.
When using the GameplayTagsIf you want to add tags, simply add the necessary tags from the panel as they are required.
In the IdealTwinBaseCharacter variable add new subtag anywhere you want. Being GameplayTags you can organize your tags as you need without affecting the performance.

It is important to specify the source to be used to save the tag when adding the tag.

Having the new tag already assigned to the SwitchPawnTag will be used as the tag of the current pawn.

How to make changes of possession
From the PlayerController you can do the posession using the SwitcherComponent using the tag you want to find and use and it will do it directly:

From outside the PlayerController
you can take the component if it exists and make the change. Although this can be done, it is recommended that the implementation be done directly in the one to be used.

This is an example of how the implementation would look like inside the PC_ITw_Interior
to make camera changes

PawnSwitchInterface
This interface is used in the Pawns/Characters
that you want to integrate with the GamePlayTag
. Internally, the component will track all actors at the level that implement this interface to perform the possession if they match the specific tag being searched for.
Classes that inherit from IdealTwinWalkCharacter
, IdealTwinOrbitalCharacter
, IdealTwinBaseCharacter
already implements from C++ the auto registration and the assigned tags.
It is recommended to always create new pawns that inherit from IdealTwinBaseCharacter
so that the implementation is already integrated.