Replicated Swimming Component

This project allows you to easily and quickly add fully replicated and animated Swimming with abilities such as sprint swimming, underwater diving and jump diving into water through Blueprint Actor Components.

Customize it, Make it yours - Allows you to customize the system even in real-time.
Plug & Play - Simple Actor Components to be initialized and the rest is history.
Simple Blueprints - The entire system is in blueprints, coded with optimized industry standards. It is also compatible with C++.
Fully Replicated - The entire system is replicated over the network and can be played in multiplayer.
Swimming - Fully customizable swimming component. Control everything from the speed to the rotation rate and capsule size of your character.
Underwater Diving - Vertical diving with key inputs or using the character’s control rotation.
Sprint Swimming - Customizable speeds for sprint swimming and sprint diving.
Jump Diving - Specific animations for jumping into the water

Initial Setup

Collision Setup for Existing Projects
Open your Project Settings and head into Collision under the Engine category
Create a New Object Channel called Water set to Ignore
Under AuroraDevs_RLC/Blueprints/Actors, open BP_SwimmingWater
Click on Static Mesh Component in the Components panel
Scroll down until the Collision category in the Details panel
Set the Collision Presets to Custom and the Object Type to Water and make sure to check GenerateOverlapEvents and Overlap Pawn
Under AuroraDevs_RLC/Blueprints/Characters, open BP_ThirdPersonCharacter and select the Capsule Component. Under its collision settings, make sure that it can overlap Water
Under AuroraDevs_RLC/Blueprints/Components, open BP_SwimmingComponent
Under the Variables panel, expand Utilities - Traces and click on TraceObjectTypes
Under the Details panel, click on the + sign to add an array element if it doesn’t already exist and set its default value to Water
Compile, Save and Exit

Adding Water to Your Level
BP Swimming Water: is an actor which you can drop into your world to get a swimmable water.
Static Mesh Component: You can set the water mesh and choose our pool mesh or you can make your own. Make sure that its object type is set to Water and that it can generate overlap events on Pawns.
Underwater Bounds (Box Collision): The only use of this box is to set the bounds of the underwater post process component which is activated when the camera goes under water. In the construction script, you’ll find a bit of code which makes the box automatically try to fit the mesh exactly.
UnderwaterPostProcess: This is activated when the camera goes under the water. We have chosen a simple post process material based on the water provided by the UE4.26 Water Plugin.

BP Swimming Water_Plane:
If you want to use a Plane Static Mesh instead of a full box mesh like in the picture above, you can use BP_SwimminWater_Plane. But in this case, the Underwater Bounds box collision will need to serve as the bounds of your water since a plane doesn’t have any height. As such, the underwater bounds’ collision settings should be set like this
In this blueprint, the box collision will automatically fit the plane’s mesh but you will need to scale the Z to your liking.

Water Physics Volume:
⚠️Unfortunately, in order for swimming to work, it is mandatory for you to place a PhysicsVolume in the level for each swimmable water actor.
Find the Physics Volume in the Place Actor tab and place it into your level.
Make sure to set Water Volume to TRUE in the Physics Volume settings
Make sure that the physics volume can generate overlap events on Pawns.
In the World Outliner, attach the volume to your BP_SwimmingWater and reset its Location to (0, 0, 0)
Scale the volume and make sure the volume fits your water mesh perfectly. If you need it to be a different shape, you can change it under Brush Settings.

Component Setup
The project comes of course with its own character class ready for usage for those who want to start a fresh project. Nonetheless, adding the components to your own character classes is as simple as ABC.
Open you character blueprint
Click on Add Component
Search for and select BP_SwimmingComponent
Initialize the components in the Construction Script or On Begin Play by using the OnInitialize function of the corresponding component and plugging in the character (Reference to self). You can also copy these scripts from our BP Character class
Plug in your inputs. You can either define these in your Project Settings under Input or directly use the Input Event Keys for testing. You can also copy these scripts from our BP Character class
If you want your character to follow the control rotation while underwater, plug in your Move Forward as follow:

Go to your animation blueprint, get a reference to the swimming component. You can do this in any manner of your choosing but if you want to avoid casts and interfaces, simply get the component on Begin Play
In the Event Blueprint Update Animation, use the initialized Swimming Component to fetch these variable
In your AnimGraph, add a state called Swimming Locomotion with two transitions going to and from your Ground/Air state.
In the newly added SwimmingLocomotion state, plug in the BS_DiveSpeedDirection and BS_SwimSurfaceSpeed blend spaces as such
⚠️If you are not using the Unreal Mannequin Rig, you will need to retarget these assets or use your own.
If you are not interested in Jump Diving into water, skip to the last step.
Create 3 more states called JumpDiveEnter, JumpDiveLoop and JumpDiveEnd.
One transition from MainLocomotion to JumpDiveEnter with the condition set as “bIsInAir AND bIsGoingToJumpDiveIntoWater”
One transition from JumpDiveEnter to JumpDiveLoop with the condition set as GetRelevantAnimTimeRemainingFraction() < 0.1
For the animation, choose the ThirdPerson_JumpDive_Start animation and make sure to disable Looping
❗ Click on the JumpDiveStart state, on the right under “Entered State Event”, type in OnJumpDove
One transition from JumpDiveLoop to JumpDiveEnd with the condition set as “NOT bIsinAir”
For the animation, choose the ThirdPerson_JumpDive_Loop animation ane make sure looping is enabled
One transition from JumpDiveEnd back to SwimmingLocomotion with the condition set as GetRelevantAnimTimeRemainingFraction() < 0.1
For the animation, choose the ThirdPerson_JumpDive_End animation and make sure to disable Looping.
❗ Click on the JumpDiveEnd state, on the right under “Entered State Event”, type in OnJumpDiveEnded
Back in the animation blueprint’s Event Graph, right click to open the context menu and look for the AnimNotify events OnJumpDove and OnJumpDiveEnded then plug them as such
Add a DefaultSlot to your AnimBP in order to play animation montages

Component Settings
Swimming and Diving
SprintSwimSpeed: Swimming speed while sprinting is active
SwimmingHalfHeight: Half height of the character when they start swimming
SwimmingRotationRate: Rotation rate of the character when they start swimming
UnderwaterSwimSpeed: Swimming speed when underwater
UnderwaterSprintSpeed: Swimming speed when underwater and sprint is active
UnderwaterDiveDownStartMontage: This is played when character is swimming on the surface and wants to dive down.
Jump Diving
bJumpDivingEnabled: If enabled, character will do special diving animations when he jumps if the jump landing location is a water body
MaxJumpDiveHeight: Maximum jump height from which jump diving is played

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
) instead.