Table of Contents

Class SplineUtils

public static class SplineUtils
Inheritance
SplineUtils
Inherited Members

Methods

AddPointsToSpline(SplineContainer, Vector3[], int, bool)

Adds a sequence of points to an existing spline

public static void AddPointsToSpline(SplineContainer splineContainer, Vector3[] positions, int splineIndex = 0, bool autoSmooth = true)

Parameters

splineContainer SplineContainer

The spline container to modify

positions Vector3[]

Positions to add

splineIndex int

Index of the spline to modify

autoSmooth bool

Whether to auto-smooth tangents

AutoSmoothTangents(Spline, float)

Automatically smooths the tangents of a spline

public static void AutoSmoothTangents(Spline spline, float tangentScale = 0.33)

Parameters

spline Spline

The spline to smooth

tangentScale float

Scale factor for tangent length (default: 0.33)

ContainerChildrenToPositionList(Transform, bool, bool)

Converts all child positions of a container transform to a list of Vector3 positions

public static List<Vector3> ContainerChildrenToPositionList(Transform container, bool includeInactive = false, bool localPositions = true)

Parameters

container Transform

The parent transform containing child objects

includeInactive bool

Whether to include inactive child objects (default: false)

localPositions bool

Returns

List<Vector3>

List of Vector3 positions of all children

CreateArcBetweenPoints(Vector3, Vector3, float, int, Transform)

Creates a path between two points with an arc

public static SplineContainer CreateArcBetweenPoints(Vector3 start, Vector3 end, float arcHeight, int pointCount = 5, Transform parent = null)

Parameters

start Vector3

Start position

end Vector3

End position

arcHeight float

Height of the arc

pointCount int

Number of points to generate (min 3)

parent Transform

Optional parent transform

Returns

SplineContainer

SplineContainer with an arcing path

CreateClosedLoopSpline(Vector3[], Transform)

Creates a closed loop spline from positions

public static SplineContainer CreateClosedLoopSpline(Vector3[] positions, Transform parent = null)

Parameters

positions Vector3[]

Positions to form the loop

parent Transform

Optional parent transform

Returns

SplineContainer

A new SplineContainer with a closed loop

CreateElevatedRoadMesh(SplineContainer, float, float, float, int, int, Transform)

Creates an elevated road mesh with side walls

public static Mesh CreateElevatedRoadMesh(SplineContainer splineContainer, float width, float height, float materialTilingMultiplier = 1, int splineIndex = 0, int segments = 100, Transform transform = null)

Parameters

splineContainer SplineContainer

The spline to follow

width float

Width of the road

height float

Height of the side walls

materialTilingMultiplier float

Multiplier for texture tiling

splineIndex int

Index of the spline to use

segments int

Number of segments for the road mesh

transform Transform

Optional transform to convert to local space

Returns

Mesh

A generated elevated road mesh with walls

CreateRibbonMesh(SplineContainer, float, float, float, int, int, bool, float, Transform)

Creates a ribbon mesh following a spline, useful for rivers, streams, or paths

public static Mesh CreateRibbonMesh(SplineContainer splineContainer, float startWidth, float endWidth, float materialTilingMultiplier = 1, int splineIndex = 0, int segments = 100, bool conformToTerrain = false, float terrainOffset = 0.1, Transform transform = null)

Parameters

splineContainer SplineContainer

The spline to follow

startWidth float

Width at the start of the spline

endWidth float

Width at the end of the spline

materialTilingMultiplier float

Texture tiling multiplier

splineIndex int

Index of the spline to use

segments int

Number of segments along the spline

conformToTerrain bool

Whether to conform to terrain height

terrainOffset float

Height offset from terrain

transform Transform

Optional transform to convert to local space

Returns

Mesh

A ribbon mesh following the spline with varying width

CreateRoadMesh(SplineContainer, float, float, bool, int, int, Transform)

Creates a road mesh from a spline path

public static Mesh CreateRoadMesh(SplineContainer splineContainer, float width, float materialTilingMultiplier = 1, bool flipDirection = false, int splineIndex = 0, int segments = 100, Transform transform = null)

Parameters

splineContainer SplineContainer

The spline to follow

width float

Width of the road

materialTilingMultiplier float

Multiplier for texture tiling (higher value = more tiling)

flipDirection bool

Whether to flip the road direction

splineIndex int

Index of the spline to use

segments int

Number of segments for the road mesh (higher = smoother)

transform Transform

Optional transform to convert to local space

Returns

Mesh

A generated road mesh

CreateSpiralSpline(Vector3, float, float, float, float, int, Transform)

Creates a spiral spline

public static SplineContainer CreateSpiralSpline(Vector3 center, float startRadius, float endRadius, float height, float rotations, int segments, Transform parent = null)

Parameters

center Vector3

Center of the spiral

startRadius float

Starting radius

endRadius float

Ending radius

height float

Height difference from start to end

rotations float

Number of full rotations

segments int

Number of segments per rotation (higher = smoother)

parent Transform

Optional parent transform

Returns

SplineContainer

SplineContainer with a spiral shape

CreateSplineFromLocalPositions(Vector3[], bool)

Creates a Spline object directly from a list of positions

public static Spline CreateSplineFromLocalPositions(Vector3[] positions, bool autoSmooth = true)

Parameters

positions Vector3[]

Array of positions in local space

autoSmooth bool

Whether to automatically smooth the tangents

Returns

Spline

A new Spline object

CreateSplineFromPositions(Vector3[], Transform, bool)

Creates a new SplineContainer with a spline from a list of world positions

public static SplineContainer CreateSplineFromPositions(Vector3[] positions, Transform parent = null, bool autoSmooth = true)

Parameters

positions Vector3[]

List of world positions to form the spline

parent Transform

Optional parent transform

autoSmooth bool

Whether to automatically smooth the tangents

Returns

SplineContainer

A new SplineContainer GameObject

CreateSplineFromPositionsList(List<Vector3>, bool)

Creates a spline from a List of Vector3 positions

public static Spline CreateSplineFromPositionsList(List<Vector3> positionsList, bool autoSmooth = true)

Parameters

positionsList List<Vector3>

List of positions in local space

autoSmooth bool

Whether to auto-smooth the tangents

Returns

Spline

A new Spline object

CreateSplineFromWorldPositions(Vector3[], Transform, bool)

Creates a Spline object directly from a list of world positions

public static Spline CreateSplineFromWorldPositions(Vector3[] worldPositions, Transform referenceTransform, bool autoSmooth = true)

Parameters

worldPositions Vector3[]

Array of positions in world space

referenceTransform Transform

Transform used to convert world to local positions

autoSmooth bool

Whether to automatically smooth the tangents

Returns

Spline

A new Spline object

CreateSplineGrid(Vector3, float, float, int, int, Transform)

Creates a grid of splines forming a network

public static List<SplineContainer> CreateSplineGrid(Vector3 origin, float width, float length, int rows, int columns, Transform parent = null)

Parameters

origin Vector3

Bottom-left corner of the grid

width float

Width of the grid (X axis)

length float

Length of the grid (Z axis)

rows int

Number of rows

columns int

Number of columns

parent Transform

Optional parent transform

Returns

List<SplineContainer>

List of SplineContainer GameObjects forming the grid

CreateTerrainFollowingSpline(Vector3, Vector3, float, int, Transform)

Creates a spline that follows terrain height

public static SplineContainer CreateTerrainFollowingSpline(Vector3 startPoint, Vector3 endPoint, float heightOffset, int segments, Transform parent = null)

Parameters

startPoint Vector3

Start position in world space

endPoint Vector3

End position in world space

heightOffset float

Offset from terrain height

segments int

Number of segments (higher = better terrain following)

parent Transform

Optional parent transform

Returns

SplineContainer

SplineContainer that follows terrain height

CreateTunnelMesh(SplineContainer, float, int, int, float, int, Transform)

Creates a tunnel mesh along a spline

public static Mesh CreateTunnelMesh(SplineContainer splineContainer, float radius, int segments = 50, int circleVertices = 12, float materialTilingMultiplier = 1, int splineIndex = 0, Transform transform = null)

Parameters

splineContainer SplineContainer

The spline to follow

radius float

Radius of the tunnel

segments int

Number of segments along the spline

circleVertices int

Number of vertices around the circumference

materialTilingMultiplier float

Texture tiling multiplier

splineIndex int

Index of the spline to use

transform Transform

Optional transform to convert to local space

Returns

Mesh

A generated tunnel mesh

DistributePooledObjectsAlongSpline(SplineContainer, Func<GameObject>, Action<GameObject>, Transform, int, List<GameObject>, int, bool, Vector3, Vector3, Vector3)

Distributes GameObjects along a spline using object pooling

public static List<GameObject> DistributePooledObjectsAlongSpline(SplineContainer spline, Func<GameObject> getPooledObject, Action<GameObject> releasePooledObject, Transform container, int objectCount, List<GameObject> existingObjects = null, int splineIndex = 0, bool alignToSpline = true, Vector3 rotationOffset = null, Vector3 forwardAxis = null, Vector3 upAxis = null)

Parameters

spline SplineContainer

The spline to distribute objects along

getPooledObject Func<GameObject>

Function to get an object from a pool

releasePooledObject Action<GameObject>

Function to release an object back to the pool

container Transform

Container transform to parent the objects to

objectCount int

Number of objects to distribute along the spline

existingObjects List<GameObject>

Optional list of existing objects to release back to the pool

splineIndex int

Index of the spline to use (default: 0)

alignToSpline bool

Whether to align objects to the spline direction

rotationOffset Vector3

Additional rotation to apply (in degrees)

forwardAxis Vector3

Which local axis should point forward along the spline

upAxis Vector3

Which local axis should align with the spline's up direction

Returns

List<GameObject>

List of positioned GameObjects from the pool

DistributePooledPrefabsAlongSpline(SplineContainer, GameObject, Transform, int, List<GameObject>, int, bool, Vector3)

Example method showing how to use DistributePooledObjectsAlongSpline with ObjectPoolPattern

public static List<GameObject> DistributePooledPrefabsAlongSpline(SplineContainer spline, GameObject prefab, Transform container, int objectCount, List<GameObject> existingObjects = null, int splineIndex = 0, bool alignToSpline = true, Vector3 rotationOffset = null)

Parameters

spline SplineContainer
prefab GameObject
container Transform
objectCount int
existingObjects List<GameObject>
splineIndex int
alignToSpline bool
rotationOffset Vector3

Returns

List<GameObject>

DistributePooledPrefabsAlongSpline(SplineContainer, GameObject, Transform, int, int, bool, Vector3)

public static List<GameObject> DistributePooledPrefabsAlongSpline(SplineContainer spline, GameObject prefab, Transform container, int objectCount, int splineIndex = 0, bool alignToSpline = true, Vector3 rotationOffset = null)

Parameters

spline SplineContainer
prefab GameObject
container Transform
objectCount int
splineIndex int
alignToSpline bool
rotationOffset Vector3

Returns

List<GameObject>

FlipNormals(Mesh)

Flips the normals of a mesh

public static void FlipNormals(Mesh mesh)

Parameters

mesh Mesh

The mesh to modify

GetClosestPointOnSpline(SplineContainer, Vector3, int, int)

Gets the closest point on a spline to a world position

public static float GetClosestPointOnSpline(SplineContainer splineContainer, Vector3 worldPosition, int splineIndex = 0, int resolution = 100)

Parameters

splineContainer SplineContainer

The spline container

worldPosition Vector3

The world position to find closest point to

splineIndex int

Index of the spline

resolution int

How many points to check (higher = more accurate but slower)

Returns

float

Normalized t value (0-1) of the closest point on the spline

GetPositionsFromSpline(Spline)

Extracts a list of all knot positions from a spline

public static Vector3[] GetPositionsFromSpline(Spline spline)

Parameters

spline Spline

The spline to extract positions from

Returns

Vector3[]

Array of Vector3 positions

MergeSplines(List<SplineContainer>, bool, Transform)

Merges multiple splines into a single spline container

public static SplineContainer MergeSplines(List<SplineContainer> splines, bool connectEndpoints = false, Transform parent = null)

Parameters

splines List<SplineContainer>

List of spline containers to merge

connectEndpoints bool

Whether to connect the endpoints of consecutive splines

parent Transform

Optional parent transform

Returns

SplineContainer

SplineContainer containing all the merged splines

NeedToFlipNormals(Mesh, Transform)

Helper method to check if mesh normals need to be flipped

public static bool NeedToFlipNormals(Mesh mesh, Transform transform = null)

Parameters

mesh Mesh

The mesh to check

transform Transform

Optional transform to convert normals to world space

Returns

bool

True if normals should be flipped

OffsetSpline(SplineContainer, float, int, int, Transform)

Offsets a spline by a given distance perpendicular to its direction

public static SplineContainer OffsetSpline(SplineContainer sourceSpline, float offset, int splineIndex = 0, int sampleCount = 20, Transform parent = null)

Parameters

sourceSpline SplineContainer

The source spline container

offset float

Distance to offset (positive = right, negative = left)

splineIndex int

Index of the spline to offset

sampleCount int

Number of samples for accuracy

parent Transform

Optional parent transform

Returns

SplineContainer

New SplineContainer with the offset path

PlaceObjectAtSplinePoint(SplineContainer, GameObject, Transform, bool, float, Vector3, Vector3, Vector3, int)

Places a single object at a specific point along a spline with precise rotation control

public static GameObject PlaceObjectAtSplinePoint(SplineContainer spline, GameObject prefab, Transform parent, bool normalizeDistance, float distance, Vector3 rotationOffset, Vector3 forwardAxis, Vector3 upAxis, int splineIndex = 0)

Parameters

spline SplineContainer

The spline container

prefab GameObject

The object to spawn

parent Transform

Parent transform for the spawned object

normalizeDistance bool

Whether the distance is normalized (0-1) or in world units

distance float

Distance along the spline

rotationOffset Vector3

Additional rotation to apply (in degrees)

forwardAxis Vector3

Which local axis should point forward along the spline

upAxis Vector3

Which local axis should align with the spline's up direction

splineIndex int

Index of the spline to use (default: 0)

Returns

GameObject

The instantiated GameObject or null if failed

ReverseSpline(SplineContainer, int)

Reverses the direction of a spline

public static void ReverseSpline(SplineContainer splineContainer, int splineIndex = 0)

Parameters

splineContainer SplineContainer

The spline container to modify

splineIndex int

Index of the spline to reverse

SamplePointsAlongSpline(SplineContainer, float, int)

Samples points along a spline at regular distance intervals

public static Vector3[] SamplePointsAlongSpline(SplineContainer splineContainer, float spacing, int splineIndex = 0)

Parameters

splineContainer SplineContainer

The spline container to sample

spacing float

Distance between samples

splineIndex int

Index of the spline to sample

Returns

Vector3[]

Array of sampled world positions

SpawnObjectsAlongSpline(SplineContainer, GameObject, Transform, LayerMask, bool, bool, float, float, int)

Spawns objects along a spline at regular intervals

public static void SpawnObjectsAlongSpline(SplineContainer spline, GameObject prefab, Transform objectContainer, LayerMask groundLayers, bool snapToGround, bool alignToSpline, float groundOffset, float spacing, int splineIndex = 0)

Parameters

spline SplineContainer

The spline container to follow

prefab GameObject

The object to spawn

objectContainer Transform
groundLayers LayerMask
snapToGround bool
alignToSpline bool
groundOffset float
spacing float

Distance between objects

splineIndex int

Index of the spline to use (default: 0)

SpawnObjectsAlongSplineAdvanced(SplineContainer, GameObject, Transform, LayerMask, bool, bool, float, float, Vector3, int)

Spawns objects along a spline at regular intervals with advanced rotation control

public static void SpawnObjectsAlongSplineAdvanced(SplineContainer spline, GameObject prefab, Transform objectContainer, LayerMask groundLayers, bool snapToGround, bool alignToSpline, float groundOffset, float spacing, Vector3 rotationOffset, int splineIndex = 0)

Parameters

spline SplineContainer

The spline container to follow

prefab GameObject

The object to spawn

objectContainer Transform

Container to parent spawned objects to

groundLayers LayerMask

Layers to raycast against for ground snapping

snapToGround bool

Whether to snap objects to ground

alignToSpline bool

Whether to align objects to spline direction

groundOffset float

Height offset from ground when snapping

spacing float

Distance between objects

rotationOffset Vector3

Additional rotation to apply to objects (in degrees)

splineIndex int

Index of the spline to use (default: 0)

SpawnObjectsAlongSplineAdvanced(SplineContainer, ObjectPool<GameObject>, Transform, LayerMask, bool, bool, float, float, Vector3, int)

public static void SpawnObjectsAlongSplineAdvanced(SplineContainer spline, ObjectPool<GameObject> prefabPool, Transform objectContainer, LayerMask groundLayers, bool snapToGround, bool alignToSpline, float groundOffset, float spacing, Vector3 rotationOffset, int splineIndex = 0)

Parameters

spline SplineContainer
prefabPool ObjectPool<GameObject>
objectContainer Transform
groundLayers LayerMask
snapToGround bool
alignToSpline bool
groundOffset float
spacing float
rotationOffset Vector3
splineIndex int

SubdivideSpline(SplineContainer, int, int, bool)

Subdivides a spline by adding additional points between existing knots

public static void SubdivideSpline(SplineContainer splineContainer, int subdivisions, int splineIndex = 0, bool preserveTangents = false)

Parameters

splineContainer SplineContainer

The spline container to subdivide

subdivisions int

Number of points to add between each existing pair of knots

splineIndex int

Index of the spline to subdivide

preserveTangents bool

Whether to preserve tangent information (true) or auto-smooth (false)

TransformsToPositionList(List<Transform>)

Converts a list of transforms to a list of their world positions

public static List<Vector3> TransformsToPositionList(List<Transform> transforms)

Parameters

transforms List<Transform>

List of transforms to convert

Returns

List<Vector3>

List of Vector3 positions

TransformsToPositionList(Transform[])

Converts an array of transforms to a list of their world positions

public static List<Vector3> TransformsToPositionList(Transform[] transforms)

Parameters

transforms Transform[]

Array of transforms to convert

Returns

List<Vector3>

List of Vector3 positions

UpdateObjectsAlongSpline(List<Vector3>, List<GameObject>, bool, Vector3, bool, Vector3, Vector3)

Updates the positions and rotations of objects based on a spline created from updated positions

public static SplineContainer UpdateObjectsAlongSpline(List<Vector3> positions, List<GameObject> objects, bool alignToSpline = true, Vector3 rotationOffset = null, bool distributeEvenly = true, Vector3 forwardAxis = null, Vector3 upAxis = null)

Parameters

positions List<Vector3>

List of Vector3 positions to create the spline from

objects List<GameObject>

List of GameObjects to update positions and rotations for

alignToSpline bool

Whether to align objects to the spline direction

rotationOffset Vector3

Additional rotation to apply (in degrees)

distributeEvenly bool

If true, distributes objects evenly along spline; if false, tries to match positions to closest spline points

forwardAxis Vector3

Which local axis should point forward along the spline

upAxis Vector3

Which local axis should align with the spline's up direction

Returns

SplineContainer

The temporary SplineContainer created for the update (null if failed)

UpdateObjectsAlongSplineAndCleanup(List<Vector3>, List<GameObject>, bool, Vector3, bool, Vector3, Vector3)

Updates the positions and rotations of objects based on a spline created from updated positions, and automatically cleans up the temporary spline

public static void UpdateObjectsAlongSplineAndCleanup(List<Vector3> positions, List<GameObject> objects, bool alignToSpline = true, Vector3 rotationOffset = null, bool distributeEvenly = true, Vector3 forwardAxis = null, Vector3 upAxis = null)

Parameters

positions List<Vector3>

List of Vector3 positions to create the spline from

objects List<GameObject>

List of GameObjects to update positions and rotations for

alignToSpline bool

Whether to align objects to the spline direction

rotationOffset Vector3

Additional rotation to apply (in degrees)

distributeEvenly bool

If true, distributes objects evenly along spline; if false, tries to match positions to closest spline points

forwardAxis Vector3

Which local axis should point forward along the spline

upAxis Vector3

Which local axis should align with the spline's up direction