Overview
The ACF Mount System provides a flexible and robust way to implement mounting and dismounting mechanics in Unreal Engine games. It allows characters to interact with mountable entities, take control of them, and seamlessly switch between mounted and on-foot gameplay. This system supports both AI and player-controlled mounts, as well as complex interactions like custom mount points and rider animations.
Core Features
Mounting and Dismounting:
Supports multiple mount points.
Handles possession logic for rider and mount.
Allows dismounting at predefined or dynamic points.
Replication:
Fully replicated for multiplayer environments.
Syncs rider and mount states across the network.
Customizable Interactions:
Custom mount points using UACFMountPointComponent.
Rider actions triggered while mounted.
Modular integration with animation systems.
AI and Player Integration:
Compatible with both AI and player characters.
Includes logic for AI-controlled mounts.
Key Classes and Components
1. UACFMountableComponent
The primary component for defining mountable entities.
Responsibilities:
Manages mount points and their locations.
Handles the mounted state and rider assignment.
Provides functionality for triggering rider actions.
Key Properties:
bIsMounted: Tracks if the entity is currently mounted.
rider: Reference to the current rider.
mountMeshOverride: Optional override for the mount's skeletal or static mesh.
DefaultDismountPoint: Tag for the default dismount point.
Key Methods:
TriggerActionOnRider(FGameplayTag ActionState): Executes an action on the rider.
2. UACFRiderComponent
Manages the rider's interaction with mountable entities.
Responsibilities:
Handles mounting and dismounting logic for the rider.
Manages possession transitions between rider and mount.
Controls attachment and detachment to/from the mount.
Key Properties:
bIsRiding: Tracks if the character is currently mounted.
Mount: Reference to the current mount.
groupOwner: Optional reference to an AI group for AI riders.
Key Methods:
StartMount(UACFMountableComponent* mount): Initiates the mount process.
StartDismount(const FName& dismountPoint): Initiates the dismount process.
4. UACFRiderAnimInstance
Extends the character animation instance to support rider-specific animations.
Responsibilities:
Syncs rider animations with mount states.
Updates animation variables like mount speed and turn rate.
Key Methods:
NativeBeginPlay(): Initializes references to rider components.
NativeThreadSafeUpdateAnimation(float DeltaTime): Updates animation parameters based on mount state.
Workflow
Mounting Process
The rider triggers StartMount on the UACFRiderComponent.
The mount is validated via UACFMountableComponent::CanBeMounted.
The rider attaches to the mount point, and the mount state is updated.
Possession switches to the mount if needed.
Dismounting Process
The rider triggers StartDismount on the UACFRiderComponent.
The rider detaches from the mount point.
The rider's state and collisions are reset.
Possession switches back to the rider if needed.
Replication
bIsMounted and rider are replicated
Methods like OnRep_IsMounted and OnRep_Mount handle state synchronization on clients.
The system ensures smooth mounting and dismounting transitions in multiplayer games.
Customization and Extensibility
Custom Mount Points:
Add multiple UACFMountPointComponent instances to a mountable entity.
Define unique tags for each mount point.
Rider Actions:
Use TriggerActionOnRider to execute gameplay-specific actions while mounted.
Animation Integration:
Extend UACFRiderAnimInstance to implement custom rider animations.
Possession Logic:
Override HandlePossession in UACFRiderComponent for custom possession workflows.
Conclusion
The ACF Mount System provides a comprehensive framework for implementing mount and dismount mechanics. Its modularity and extensibility make it suitable for a wide range of use cases, from player-controlled mounts to AI companions and dynamic gameplay interactions.