Getting Started With The Water System

Creating A Water Object

We create a water object from the Hierarchy's Create menu:

2D Object → Game2D Water Kit → Water Object

Create 2D Water Object from the Hierarchy's Create menu

Resizing The Water Object

We resize the water object right in the scene view using the Rect Tool, or we can just provide the width and the height in the water component inspector.

Resize Water Object in the component inspector

Script Reference

// setting the size of water object
waterObject.MainModule.SetSize(new Vector2(width, height));

// getting the size of water object
Vector2 size = waterObject.MainModule.WaterSize;
float width = waterObject.MainModule.Width;
float height = waterObject.MainModule.Height;

// when the simulation runs, the water height may be different at different points
float heightAtSomeXPosition = waterObject.MainModule.GetWaterHeightAtSpcificPoint(xPositionOfSomePointInWorldSpace);

Sorting The Water Object Relative To Sprites

Before trying to sort the water object relative to sprites, we first need to make sure that the Rendering Queue property, under Rendering Options in the water material inspector, is set to Transparent.


The Rendering Queue property is set to Transparent by default.

Water Material Rendering Options

Then, under the Rendering Properties in the water component inspector, we specify the sorting layer as well as the order within that layer.

Water Component Rendering Options

Script Reference

waterObject.RenderingModule.SortingLayerID = SortingLayer.NameToID("Default");
waterObject.RenderingModule.SortingOrder = 3;

Changing The Shape Of The Water Object

We can hide or reveal parts of the water object to make it take a certain shape either by using Sprite Masks or by enabling the Mesh Mask feature under the Rendering Properties in the water component inspector.

Water Component Mesh Mask Editor - Edit Mask Inactive

Script Reference

waterObject.RenderingModule.MeshMask.IsActive = true;

To edit the mask's shape, we first need to enter the Mask Shape Editor by pressing the Edit Mask Shape button.

Water Component Mesh Mask Editor - Edit Mask Active

Then, we can tweak the mask's shape using the control points in the scene view.

  • Hold the Ctrl key and press any of the green dots to add a control point at that position.
  • Hold the Alt key and press the control point you want to remove.

Under the Rendering Options in the water material inspector, we can set the Mask Interaction property to:

  • Visible Inside Mask
  • Visible Outside Mask

Water Material Mask Interaction

If the Lock Position And Size property is toggled on, the mask will no longer update its size and position to match the water object's size and position.

Setting Up The Edge Collider 2D

If the Use Edge Collider 2D property is toggled on, we can easily edit the edge collider's polyline so it matches the mask's outline.

Setting Up The Polygon Collider 2D

We can also set up a Polygon Collider 2D to be used instead of the Box Collider 2D to detect collisions. It will also be used by the Buoyancy Effector 2D.


We will look into the other rendering properties later in the Water Visuals section.