The Swim ability starts when the character enters a trigger on the Water layer. The top of the trigger bounds is the default water-surface height, so align the collider with the visible water plane before tuning the ability.

Create the water volume

  1. Create a GameObject for the water volume.
  2. Set its layer to Water.
  3. Add a Box Collider and enable Is Trigger.
  4. Size the collider to cover the swimmable volume and align its top face with the water surface.

In the demo scene the water mesh is a child of the water trigger but this is not a requirement.

A water volume with its trigger collider aligned to the visible water surface.

Integrate a custom water surface

When another water asset animates or calculates the visible surface, keep the trigger for volume detection and set Swim’s Water Height Detection Mode to Custom. Then call SetWaterSurfacePosition with the sampled world-space y coordinate. In Collider mode the next depth calculation overwrites that value from the trigger. This example supplies height 5 after Custom has been selected:

using UnityEngine;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.AddOns.Swimming;

public class MyObject : MonoBehaviour
{
    [Tooltip("The character that contains the swim ability.")]
    [SerializeField] protected GameObject m_Character;

    /// <summary>
    /// Sets the water surface position.
    /// </summary>
    private void Start()
    {
        var characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
        var swimAbility = characterLocomotion.GetAbility<Swim>();
        swimAbility.SetWaterSurfacePosition(5f);
    }
}

Update the value whenever a dynamic water surface changes height.

With a water trigger present, the method expects the surface’s world-space y coordinate, not an offset from the trigger or character. Sample near the character and update Swim as the character moves. The current triggerless path treats the supplied height as depth; retain the trigger for this workflow. See the limitation and dynamic sampling example on Swim.

Use multiple water volumes

Split irregular bodies of water into multiple triggers when one box would include caves, shore terrain, or other dry regions. Keep adjacent volumes overlapping enough that the character does not briefly exit all valid water while crossing the seam. Their top faces should agree unless a custom integration is updating the height.

For rivers or moving water, triggers still define where swimming is valid; they do not by themselves apply a current. Apply current forces or destination changes through project-specific logic while Swim owns the posture and buoyancy. Verify that the additional motion does not push the character outside the valid volume every frame.

Shape the shoreline

The trigger can begin before the visible water, but Swim starts only after the character reaches Start Swim Depth. This allows the character to wade through a shallow edge and transition later. Use the volume and depth together instead of placing the trigger exactly where the swim animation should begin.

At exits, make the trigger large enough to contain the character until normal ground locomotion has a stable surface. A volume that ends at the visual water line can stop Swim while the character is still too deep or too far from shore.

Verify in Play Mode

Walk into the volume at several shoreline points. Swim should start at the configured depth, surface movement should follow the visible water height, and normal locomotion should resume after leaving the trigger. If the character floats above or below the mesh, compare the collider top or SetWaterSurfacePosition value with the water plane’s world-space y position.

Also cross every boundary between adjacent volumes and test a teleport directly into deep water. A one-frame stop at a seam indicates a gap or conflicting entry/exit integration calls rather than a buoyancy setting.