Query surface height and velocity from a Water Source or Water Object.

Coordinate system

physicalXY is the world gameplay position. virtualZ is distance across the water in metres. Depth01 is normalized from 0 at the near shore to 1 at the far shore. EffectiveVirtualZ resolves the actual depth lane.

Surface queries

SettingEffect
actor.TryGetSurface(out sample)Reads the cached surface in the Water Object’s assigned lane.
water.TryGetSurface(physicalXY, virtualZ, out sample)Reads the cached surface at an explicit world XY position and virtual depth.
sample.IsReadyUse this check for a reaction that needs a fresh height.
sample.IsUsableAccepts usable fallback data. Check Status and SampleAgeSeconds when age matters.

Call component APIs on Unity’s main thread. Surface queries read cached data. A successful query can return a warming or stale sample.

using ModernPlatformerWater;

public static class Waterline
{
    public static bool TryReadHeight(
        VolumeWaterActorRenderer actor, out float height)
    {
        height = 0f;
        if (actor == null || !actor.TryGetSurface(out var sample)
            || !sample.IsReady)
            return false;

        height = sample.Height;
        return true;
    }
}

Use the height when the method returns true. While the source warms up, keep the last valid height or defer the reaction.

Further reference

Open Tools → Modern Platformer Water → Start Here — workflow guide → Scripting API for controller and wake examples.