Riders

The Rider is your main character or the character your player intends to control.   This is not specific to a single character and could be multiple characters that the player can switch between.  Either way a Rider in the PNMS system is any Pawn or Character that the player can have get onto a Mount or into a Vehicle.

References

For a more comprehensive demonstration of how the interfaces and components are implemented for the riders, download the Demo Projects and inspect the following Classes listed below.  Additionally these plugins are designed to be dropped into your project as they are and form a basis for your implementation if you just want to get started quickly.  To Download the Demos see Quick Start Guide

Mounting System Tutorial Core (MSTC)

BP_MST_RiderCharacterBase

This blueprint represents a generic blueprint implementation for all Riders based on the Character class.  It has no Mesh or Animations associated with it.

Mounting System Tutorial (MST)

BP_MST_Rider

This is a child class of the BP_MST_RiderCharacterbase blueprint.  It has been given a Skeletal Mesh and an Animation Blueprint.

Advanced Mounting System (AMS)

AmsRiderCharacter

This C++ class forms the base class to the Character Based Riders in the Advanced System.  It does not define any Mesh or Animations to use with it. 

BP_AMS_RiderCharacter

This Blueprint class is a child class of the AAmsRiderCharacter.  Primarily this class gives the rider a mesh and animation blueprint.  In addition it sets the input scheme that is used by the Rider and implements a different control scheme for Riders versus Mounts which can be hot swapped when the player takes control of the mount.

Component and Interface

The Rider needs 3 things to be added to it so that it works with the PNMS System

Add MountRiderComponent

In the Components section of your blueprint add the UMountRiderComponent to it.  Alternatively in C++ declare the UMountRiderComponent as a variable and create it in the constructor of the Rider Class.  This component has most of the functionality you will need to implement the following interfaces.

Add IADMUnifiedControllerPawn Interface

For blueprints, in the Interface list in Class Settings add the Unified Controller Pawn Interface.  This interface's purpose is to act as a unifying method of retrieving the Core Actor types of Controller, Rider, and Mount between these three actor type.  Each of the

Add the IMountRider Interface

In the Inteface list in Class Settings add the IRiderController Interface.  This interface's purpose is to give the external world access to key functionalities and information kept within the URiderControllerComponent.

MountRiderComponent Settings

The URiderControllerComponent has a few settings to keep in mind.

Flag: AllowOverrideMovementReplication

This flag is on by default.  It allows the PNMS system to override movement replication automatically during the Mounting and Dismounting Process.  If this flag is disabled then you will need to manually call the function UMountRiderComponent::SetMovementReplicaiton(bEnableReplication, bOnlyAllowAutonomousTickPose) at some point in the interface functions. 

Enabling and Disabling Movement Replicaiton by the PNM System allows for smooth motion while the character is mounted as the server is not trying to perform movement corrections for Characters or Pawns with Movement Components.

Flag: AllowCollisionOverride

This flag is on by default.  It allows the PNM System to override the Pawn's collision system automatically during the Mounting and Dismounting Process.   If this flag is disabled then you will need to manually call the function IMountRiderInterface::SetRiderCollisionEnabled(bIsEnabled) at some point during mounting and dismounting process.

Generally you will need to disable or change the collision settings of your rider while mounted.  This stops the Unreal Collision system from going crazy and launching the rider and mount into the sky as the two parts self collide with each other, it also can help with preventing the camera of your pawn from being blocked by collision of the rider or the mount.

Flag: MountingPossessionBehavior

This is an advanced option to determine how the mounting system performs Possession of the mount when a player is the driver.  Generally you can leave this untouched unless you need something very specific out of the mounting system.  There are three general options you can choose from

  1. Rider Finished Moving - Default option.  Possession of the Mount will occur when the rider finishes moving to the mounting point's location.
  2. Rider Finished Mounting - Possession of the Mount will occur when the rider's mounting has completed after the mount animation has finished and they are seated on the mount.
  3. Manual - Tells the Mounting System that you will manually call the possession logic.

If you are going to use Manual Possession that means you will need to call the possession logic on the mount manually if the player is the Driver.  In general the Rider tells the controller when it is ready to perform possession and calls the function UMountRiderComponent::AllowControllerToPossessMount() which you will need to call manually at some point during the mounting process.

Flag: MountingAttachmentBehavior

This is an advanced option to determine how the mounting system performs Rider Attachment to the mount.  Generally you can leave this untouched unless you need something very specific out of the mounting system.  There are three general options you can choose from

  1. Rider Finished Moving - Default option.  Attachment to the Mount will occur when the rider finishes moving to the mounting point's location.
  2. Rider Finished Mounting - Attachment to the Mount will occur when the rider's mounting has completed after the mount animation has finished and they are seated on the mount.
  3. Manual - Tells the Mounting System that you will manually call the attachment logic.

If you are going to use Manual Attachment that means you will need to call the attachment logic on the mount manually if the player is the Driver.  In general the Rider tells the controller when it is ready to perform attachment and calls the function UMountRiderComponent::AttachRiderToMount() which you will need to call manually at some point during the mounting process.

Flag: DismountPossessionBehavior

This is an advanced option to determine how the mounting system performs Possession of the rider when a player is dismounting and was a driver.  Generally you can leave this untouched unless you need something very specific out of the mounting system.  There are three general options you can choose from

  1. Rider Finished Dismounting - Default option.  Possession of the Rider will occur when the rider finishes dismounting and the dismount animations have finished playing.
  2. Immediately - Possession of the Rider occurs immediately upon dismounting before the dismount animation begins.
  3. Manual - Tells the Mounting System that you will manually call the possession logic.

If you are going to use Manual Possession that means you will need to call the possession logic on the rider manually if the player is the Driver.  In general the Rider tells the controller when it is ready to perform possession and calls the function UMountRiderComponent::AllowControllerToPossessRider() which you will need to call manually at some point during the mounting process.

Flag: DismountingAttachmentBehavior

This is an advanced option to determine how the mounting system performs Detachment of the rider.  Generally you can leave this untouched unless you need something very specific out of the mounting system.  There are three general options you can choose from

  1. Rider Finished Dismounting - Default option.  Detachment of the Rider will occur when the rider finishes dismounting and the dismount animations have finished playing.
  2. Immediately - Detachment of the Rider occurs immediately upon dismounting before the dismount animation begins.
  3. Manual - Tells the Mounting System that you will manually call the detachment logic.

If you are going to use Manual Detachment that means you will need to call the detachment logic on the rider manually.  In general the Rider tells the controller when it is ready to perform detachment and calls the function UMountRiderComponent::DetachRiderFromMount() which you will need to call manually at some point during the mounting process.

Flag: RelativeMeshLocation

This is a very specific setting for your Rider's Mesh, either static or skeletal which must be set if your mesh components have any sort of offset value..  After Dismounting the detachment logic of unreal has a tendency to alter the relative position of the character's mesh.  This configuration value resets it to the specified relative mesh location to ensure the character does not get strange offset positions that you do not want.  

You can automate the saving and loading of this value by using the Blueprint ConstructionScript can calling UMountRiderComponent::SetRelativeMeshLocation(inRelativeLocation)

Flag: RelativeMeshRotation

This is a very specific setting for your Rider's Mesh, either static or skeletal which must be set if your mesh components have any sort of non-zero rotation value.  After Dismounting the detachment logic of unreal has a tendency to alter the relative rotation of the character's mesh.  This configuration value resets it to the specified relative mesh rotation to ensure the character does not get strange offset positions that you do not want.  

You can automate the saving and loading of this value by using the Blueprint ConstructionScript can calling UMountRiderComponent::SetRelativeMeshRotation(inRelativeRotation)

Delegate: OnRiderAttachedToMount

Called when the rider is properly attached to the Mount during Mounting

Delegate: OnRiderDetachedFromMount

Called when the rider is detached from the mount during dismounting.

Implement the IADMUnifiedControllerPawn Interface

Implementing the functions of the IADMUnifiedControllerPawn interface is fairly straight forward and is similar to the Controller and Mount setup.

PrepareToMount

This function is a preparatory function called by the Controller to make sure that any necessary prerequisites needed for Mounting to Proceed.  On the Rider this allows the controller to detect if the Rider is ready to perform mounting for any reason.  If this function returns false then the entire mounting process stops.  

For the most basic implementations you can simply return true but there maybe some reasons you would want to return false.  Your game may require a player to obtain a key item or unlock the ability to have a mount first.  This can be a place to check if the player has achieved the prerequisite.  This function also exists on the Controller and the Mount as well so each of these three classes can define rules about canceling a mounting operation.

Return

  • bool - If this operation returns false then the mounting process will give an error return and stop the mounting operation.

Implementation

For the demo purposes this function simply returns true.

PrepareToDismount

This function is a preparatory function called by the Controller to make sure that any necessary prerequisites needed for Dismounting to Proceed.  On the Rider this allows the controller to detect if the Rider is ready to perform dismounting.  If this function returns false then the entire dismounting process stops.  For the controller you can assume to always return true for this function, but there maybe reasons to return false. 

You may have certain mounts that are on a fixed path that move through the world with the player but are not directly controlled by the player.  You may need players to stay sitting and enjoy the trip rather than dismount randomly. 

Return

  • bool - If this operation returns false then the mounting process will give an error return and stop the mounting operation.

Implementation

For the demo purposes this function simply returns true.

IsMounted

This function simply returns if the UMountRiderComponent is in Mounted Mode. 

Return

  • bool - if true, then the rider is currently mounted or mounting, but may not be seated. If false then the rider is not mounted nor are they mounting

Implementation

Return the function  UMountRiderComponent::IsMounted()

GetCharacterPawn

This function allows you to easily get the original Pawn of the player.

Return

  • APawn - Get the Pawn that the player or AI is represented by as the Rider.

Implementation

Return the function UMountRiderComponent::GetOwner() or self in Blueprints

GetCharacterMount

This function allows you to easily get the current mount of the player or AI entity. 

Return

  • AActor - Get the Actor that represents the mount the rider is mounted to

Implementation

Return the function UMountRiderComponent::GetCurrentMount()

GetCharacterController

This function allows you to easily get the controller of the player or AI entity. 

Return

  • AController - Get the controller for the Rider, should always be the true controller for the rider not the current controller that maybe possessing it.

Implementation

Return the function UMountRiderComponent::GetRiderController()

Implement the IMountRider Interface

Implementing the functions of the IMountRider interface is fairly straight forward.

StartPawnMounting

This interface function is called by the Controller to signal to the Rider that it should start the Mounting process.  This function is part of a chain of functions that begins with the URiderController::BeginMountingActor() operation.  This function is how the Controller function communicate the to Rider to start mounting.

Parameters

  • NewMountActor - The new mount for the Rider

  • LinkedActor - The Linked actor (if any) that the pawn is mounting to.  This will be null if the seat they are mounting to does not have a linked actor.

  • MountingResponse - an FMountActionResponse struct which gets transported through mounting chain

Return

  • bool - If this operation returns false then the mounting process will give an error return and stop the mounting operation.

Implementation

Return the function UMountRiderComponent::MountPawn(newMountActor, newLinkedActor, MountingResponse)

StartPawnMountingToSeat

This interface function is called by the Controller to signal to the Rider that it should start the Mounting process for a specific seat.  This function is part of a chain of functions that begins with the URiderController::BeginMountingActorToSeat() operation.  This function is how the Controller function communicate the to Rider to start mounting a specific seat.

Parameters

  • NewMountActor - The new mount for the Rider

  • LinkedActor - The Linked actor (if any) that the pawn is mounting to.  This will be null if the seat they are mounting to does not have a linked actor.

  • SeatId - the identifier of the seat on the mount that the rider will be mounted to.

  • MountingResponse - an FMountActionResponse struct which gets transported through mounting chain

Return

  • bool - If this operation returns false then the mounting process will give an error return and stop the mounting operation.

Implementation

Return the function UMountRiderComponent::MountPawnToSeat(newMountActor, newLinkedActor, SeatId, MountingResponse)

DismountPawn

This interface function is called by the Controller to signal to the Rider that it should start the Mounting process for a specific seat.  This function is part of a chain of functions that begins with the URiderController::BeginDismountingActor() operation.  This function is how the Controller function communicate the to Rider to start dismounting

Parameters

  • OldPawnMount- The actor that is being dismounted.

  • MountingResponse - an FMountActionResponse struct which gets transported through mounting chain

Return

  • bool - If this operation returns false then the dismounting process will give an error return and stop the mounting operation.

Implementation

Return the function UMountRiderComponent::DismountPawn(newMountActor, Response)

MoveToMountingLocation

This function is called to allow you to implement a method of moving the character to a desired location.  For the Demo we do not implement this at all, allowing the PNM System to automatically teleport the player to the mounting location.  If you want to see an example or use an already implemented version of this check out the Advanced Mounting System (AMS) plugin.

Parameters

  • Location - The desired location you want to move the Rider to

  • Orientation - The orientation you want to the character face.

Return

  • bool - if this function returns false it will teleport the player to the location with the orientation specified.  If this function returns true, then the PNM system assumes you will be handling the movement and it waits for that to be finished.   You must call IMountRiderInterface::OnMoveToLocationCompelete() manually to continue mounting.

Implementation

For Demo purposes we leave this blank and return false.

For a more robust implementation of this see the Advanced Mounting System Plugin which implements an auto-move feature to get the player to move to the mount automatically.

OnMountingPawnFinished

This function is executed by the PNM System as the final function signaling mounting is finished.  This function sets many of the final settings on client and server such as the flag indicating the pawn is seated and not just mounting.  If you are playing mounting animations for the character this function can be called through the "Mounting Finished" Anim Notify.

Parameters

  • NewMountActor - The new mount that the character has finished mounting.

Return

  • bool - Should always return true.  Safe to return False  as it will not stop the mounting system or throw an error.  This return only exists to force this function to remain a function and not an Event.

Implementation

Return the function UMountRiderComponent::DismountPawn(newMountActor, MountingResponse)

OnDismountingPawnFinished

This function is executed by the PNM System as the final function signaling dismounting is finished.  This function sets many of the final settings on client and server such as the flag indicating the pawn is mounted or not.  If you are playing mounting animations for the character this function can be called through the "Dismounting Finished" Anim Notify.

Parameters

  • NewMountActor - The new mount that the character has finished mounting.

Return

  • bool - Should always return true.  Safe to return False  as it will not stop the dismounting system or throw an error.  This return only exists to force this function to remain a function and not an Event.

Implementation

Return the function UMountRiderComponent::DismountPawn(newMountActor, MountingResponse)

OnChangeToNewSeatCompleted

This function is executed by the PNM System as the final function signaling a seat change has finished.  This function sets many of the final settings on client and server.  If you are playing mounting animations for the character this function can be called through the "ChangeSeat Finished" Anim Notify.

Return

  • bool - Should always return true.  Safe to return False  as it will not stop the dismounting system or throw an error.  This return only exists to force this function to remain a function and not an Event.

Implementation

Return the function UMountRiderComponent::PawnFinishedChangingSeats()

OnMoveToMountingLocationCompleted

This function is called through various methodologies available to you to signal that the character has properly moved into its desired location to begin Mounting.  Specifically if the function IMountRiderInterface::MoveToMountingLocation() returns false then this function is immediately executed. 

Return

  • bool - Should always return true if you have handled this function.

Implementation

return the function UMountRiderComponent::MoveToMountingLocationComplete().

UpdateRiderMovementMode

The PNM System calls this function on the Rider to update its overall movement mode.

Parameters

  • IsMounted- If true the movement mode of the Pawn should be updated to reflect a Mounted State

Return

  • bool - Generally this tells the PNM System that you have properly handled the Movement update.  It will issue a warning if this returns false.

Implementation

Using the IsMounted flag pass in the negated value (using not) into the function UMountRiderComponent::EnablePawnMovementComponent(!isEnabled).  

Additionally here I also use the IsMounted flag to swap between Walking and Custom Movement Mode for the Movement Component of the character by calling  UCharacterMovementComponent::SetMovementMode(MovementMode).

Finally you can optionally set the flag UCharacterMovementComponent::IgnoreClientMovementErrorChecksAndCorrection = isMounted.  This may reduce some jitters if you are seeing any for mounts that do not natively have movement prediction such as normal Pawns and apparently WheeledVehicles.

SetRiderCollisionEnabled

This function is called by the PNM System during Mounting and Dismounting so that you can adjust the collision settings of your Rider.

Parameters

  • Should Enable - Flag from the PNM System indicating the character is in the mounting state if true or unmounting state if false.

Return

  • bool - Generally should always return true.  This tells the PNM system that you have handled collision enabling or disabling.  If false is returned it assumes you have not implemented this function and gives a warning but continues the mounting and dismounting process.

Implementation

Using the Should Enable flag decide on the Collision response you want to have for the UMeshComponent::SetCollisionEnabled(ECollisionEnabled) .  For Demos if ShouldEnable is false then we are going to use "NoCollision" Value.  If ShouldEnable is true then we will use "Collision Enabled (Query and Physics)" as the Value.

For each of your character's Mesh Components (this includes all static or skeletal meshes) call the function UMeshComponent::SetCollisionEnabled(ECollisionEnabled).  

Return true to indicate to the PNM System that we have taken care of Collision.

IsSeatedOnMount

This function is used to indicate that the Rider is not only Mounted but that they are also Seated on the Mount and ready to move or take control.

Return

  • bool - Should return true if the character is seated on the mount.

Implementation

Return the function UMountRiderComponent::IsSeated().

Quite often this function will be called on tick due to animation or other systems.  Always validate that the UMountRiderComponent is valid and has not been garbage collected (Usually during project shut down so we avoid the UE error popup).

IsDriver

This function is sued to get the flag indicating that the Rider is the current Driver of the Mount.

Return

  • bool - Should return true if the rider is the Driver.

Implementation

Return the function UMountRiderComponent::IsDriver().

GetSeatId

Returns the Rider's Current Seat ID

Return

  • int32 - The numeric identifier of the Seat

Implementation

Return the function UMountRiderComponent::GetSeatId().

Quite often this function will be called on tick due to animation or other systems.  Always validate that the UMountRiderComponent is valid and has not been garbage collected (Usually during project shut down so we avoid the UE error popup).

GetRiderMesh

This function simply returns the main Mesh of your character.  Despite the fact that the mounting system attaches the whole character to the mesh of the mount, during dismounting the Unreal Engine Detachment logic tends to reset the relative locations and rotations of mesh components in Characters Classes.  This function is used by the PNM System to appropriately correct that issue by using the RelativeMeshLocation and RelativeMeshRotation properties we setup.

Return

  • UMeshComponent - the main body mesh component.

Implementation

Return you Mesh Component you are using.

GetMountRiderComponent

This function serves as a catch all to allow you to retrieve the URiderControllerComponent directly and call functions and get information out of it without having to leverage an existing interface function.  Additionally you should create custom interfaces in C++ or blueprint to make it easier to get these bits of information.

Return

  • UMountRiderComponent - The component for the Rider

Implementation

Return the UMountRiderComponet itself

GetAllRiderSkeletalMeshes

This function is used to retrieve a list of skeletal meshes for the rider that need to continue to perform animation updates in a multiplayer game due to a Setting in Unreal that will stop ticking skeletal animations on Dedicated servers.  If you are not using animations to trigger the finalizing events OnMountingPawnFinished(), OnDismountingPawnFinished(), and OnChangeToNewSeatcompleted() then this function can be ignored.

Return

  • TArray<SkeletalMeshComponent> - An array of Skeletal mesh Components that should be updated.

Implementation

Return the UMountRiderComponet itself

PlayMountingAnimation

This function is a hook to allow you to play an animation to show the character getting in or onto a Mount or Vehicle.  For the demo we leave this function unimplemented and return false.

Parameters

  • Position - This is the relative direction that the mount has calculated you are standing relative to it.  This is calculated by the mount using the funciton IMountablePawnInterface::GetRelativeMountDirection().

Return

  • bool - return true if you want to tell the PNM System that you are playing an animation for mounting a rider.  Return false and the PNM System will proceed with the mounting process.

Implementation

For Demo purposes we leave this blank and return false.

For a more robust implementation of this see the Advanced Mounting System Plugin which implements a demo animation on how to mount a character into a seat with animatons.

PlayDismountingAnimation

This function is a hook to allow you to play an animation to show the character getting off or out of a Mount or Vehicle.  For the demo we leave this function unimplemented and return false.

Parameters

  • Position - This is the relative direction you want the mount to get out of.  This is calculated by the mount function IMountablePawnInterface::GetRelativeDismountDirection().

Return

  • bool - return true if you want to tell the PNM System that you are playing an animation for mounting a rider.  Return false and the PNM System will proceed with the mounting process.

Implementation

For Demo purposes we leave this blank and return false.

For a more robust implementation of this see the Advanced Mounting System Plugin which implements a demo animation on how to mount a character into a seat with animations.

PlayMoveToSeatAnimation

This function is a hook that allows you to play an animation and move the character to a specific seat.  For the Demo we leave this function unimplemented and returns false.

Parameters

  • CurrentSeatId - The id of the new seat the character is moving to

  • OldSeatId - The id of the old seat the character moved from

Return

  • bool - return true if you want to tell the PNM System that you are playing an animation to move the character into its new seated position.  Return false and the PNM System will proceed with the seat changing process.

Implementation

For Demo purposes we leave this blank and return false.

For a more robust implementation of this see the Advanced Mounting System Plugin which implements a demo animation on how to move the character to its desired seat.

Next Section: Mounts