06 / 09
Packages/2D Softbody Pro/Runtime API & C# examples
INTERACTION & CODE
06 / 09

Runtime API & C# examples

Use forces, profile changes and shape resets; download the two complete guide scripts.

English guideSource: Unity 6000.3.13f1 · Unity Physics 2DWeb edition · 21 October 2026

Runtime component and methods#

The main component is ERAGANX.SoftBody2D.SoftBody2D. Keep a component reference and invoke the appropriate method from your gameplay code.

APIUse
Generate(out string error)Rebuild from the Sprite outline; inspect the error information on failure.
ApplyForce / ApplyImpulseDistribute force or impulse across the body.
ApplyLocalizedForce(worldPoint, force, radius)Apply a force around a world-space location.
Deform(worldPoint, displacement, radius)Explicitly edit nearby node positions. This is separate from normal collision response.
RestoreShape(strength)Apply one restoring-force update at the current pose.
ResetShape()Return to the authored root pose and clear motion.
SetProfile(profile)Apply a profile; a changed node count can regenerate the body.
Center / NodeCount / IsGeneratedRead the current center and generation state.

Use world-space points for localized force. Do not regenerate on every frame. If preserving the current deformation matters, change between profiles with different node counts outside active gameplay.

Force and reset example#

Create JellyExample.cs in your Unity project, attach it to a GameObject and assign Body and Profile. Call its public methods from your own gameplay or UI. The script below is the complete example from PDF page 5.

Download JellyExample.cs

C#
using ERAGANX.SoftBody2D;
using UnityEngine;
public class JellyExample : MonoBehaviour
{
    [SerializeField] SoftBody2D body;
    [SerializeField] SoftBodyProfile profile;
    public void PopUp()
    {
        body.ApplyImpulse(Vector2.up * 2f);
        body.ApplyLocalizedForce(body.Center, Vector2.up * 3f, 0.5f);
    }
    public void ResetJelly() => body.ResetShape();
    public void ApplyProfile() => body.SetProfile(profile);
}

Custom pointer example#

Create DragInput.cs, attach it to a GameObject and assign its Drag reference. Connect your pointer source to Press, Move and Release. The complete example from PDF page 4 does not poll input itself; the input chapter explains controller and Input System setup.

Download DragInput.cs

C#
using ERAGANX.SoftBody2D;
using UnityEngine;
public class DragInput : MonoBehaviour
{
    [SerializeField] SoftBodyDragController drag;
    public void Press(int pointerId, Vector2 screenPosition)
    {
        Vector2 world = drag.ScreenToWorld(screenPosition);
        drag.BeginDrag(pointerId, world);
    }
    public void Move(int pointerId, Vector2 screenPosition)
    {
        drag.MoveDrag(pointerId, drag.ScreenToWorld(screenPosition));
    }
    public void Release(int pointerId) => drag.EndDrag(pointerId);
}

Call ReleaseAll() on the controller when your input layer is disabled or interrupted so an active grip can end cleanly.

Using the examples#

These are guide-source examples with their original namespace and class names. They require the package in a Unity project and assigned Inspector references. They have not been compiled against a Unity project as part of this website update.

Adapted from the supplied guide · PDF pages 4–5.View source guide ↗
Keep creating.ERAGAN STUDIO.

Search a topic, setting or method across all package guides.