Unity Splines (896343)

Well hot damn, it works! Thanks.

Hello, i was trying to make smooth curves with rails, but the mesh got like this, any idea how to fix this?

Had the same issue and found 2 ways to solve it:

  • either make some kind of look at from one sleeper to another (which will still have some kind of z fighting)
  • extrude a mesh along the spline with an offset and set the tiling correct.

The second way is my way to go. Hope this helps :slight_smile:

Just a heads up, it seems that the regression with SplineAnimate is being worked on:
https://issuetracker.unity3d.com/issues/splineanimate-dot-evaluatepositionandrotation-error-when-instantiating-a-prefab-with-splineanimate-component

Trying to instanciate an object along a spline gives me this error.
I have asigned 2 prefabs. There are no empty slots.

Edit: Looks like the problem was using a prefab from the scene instead of the Asset folders.
Suggestion: If we are not supposed to pick objects from the scene ,then maybe do not offer the option in the menu.

UnityEngine.Splines.SplineInstantiate.SpawnPrefab (System.Int32 index) (at ./Library/PackageCache/com.unity.splines@2.5.2/Runtime/SplineInstantiate.cs:1043)
UnityEngine.Splines.SplineInstantiate.UpdateInstances () (at ./Library/PackageCache/com.unity.splines@2.5.2/Runtime/SplineInstantiate.cs:841)
UnityEngine.Splines.SplineInstantiate.Update () (at ./Library/PackageCache/com.unity.splines@2.5.2/Runtime/SplineInstantiate.cs:761)

So wondering, been searching for a while, is there a way to set the position of the animated gameObject manually?

Like for example, say I’d want to have the gameObject (on a scale of 0 to 1), at the position equivalent to 0.05 on the spline. Or maybe, find the closest position along the spline to a gameObject.

Trying to replicate a spline walker like those present in racing games.

There is SplineAnimate component and to modified animated property of animated gameobject you can use animation.rigging package

Is there a way to taper one or both ends of a spline when extruding it or scale the extrude on individual knots?

I am trying to split a spline at a point t.

The two new splines need to perfectly align with the original spline.

All I found is CurveUtility.Split(), but this only works with single BezierCurves.

Any idea what I can do?

Hi @GPVFX_SB :slight_smile:

To scale the extrude on individual knots, you can make your own script with SplineData points. You can look at the LoftRoadBehaviour script in the Samples. This is a really custom behavior and we will not be implementing this ourselves in the context of the Splines package.

1 Like

Hi @Esper554 :slight_smile:

If I’m understanding your question correctly, you can parent the GameObject to a root with a 0.05 Start Offset and animate the root using the SplineAnimate component.

Hi @Doomchecker :slight_smile:

You can use the SplitSplineOnKnot method. Hope it helps!

1 Like

Hey @dzamani :slight_smile:

The first part of your message is indeed a bug. I will log it.

About the second part of your message:

Baking has traditionally been a destructive process. SplineInstantiate creates dynamic hidden objects that respond to spline changes and deformations. Once the settings are finalized (and only then), the instances can be baked into the scene. At this point, they become visible items that appear in the hierarchy and can be modified and adjusted. They lose their connection to the spline, and SplineInstantiate is removed because the spline connection is broken. Therefore, avoid baking until you are ready. When you bake, it signifies that you have completed the editing process.

Hey @filod :slight_smile:

I’ll see what’s going on and why it’s still under consideration.

Update: This bug is not under our team’s purview. Although the SplineContainer component, for example, uses the list mentioned in the bug report, it is not our responsibility to fix this issue. The bug is active and the team that owns the list will address the problem as soon as possible.

1 Like

What’s the best way to insert a knot on an existing spline without affecting the spline’s curvature at all? To insert a knot at arbitrary point T, this is what I’m doing:

  • Evaluate the position at T

  • Create a new knot at that position

  • Insert the new knot into the spline

In the resulting spline, the curvature is not exactly preserved. The tangent mode is Auto for all knots, and I’m using GetAutoSmoothKnot to create the new knot, but the spline still changes.

Here’s an example. I duplicated the spline, then inserted a knot at T=0.5 (between knot index 1 and 2) on one of them to show the difference. Code for the insertion:

int index = 2;
var position = spline.EvaluatePosition(0.5f)
var newKnot = SplineUtility.GetAutoSmoothKnot(position, spline[index - 1].Position, spline[index].Position, spline.EvaluateUpVector(0.5f), spline.GetAutoSmoothTension(index));
spline.Insert(index, newKnot, TangentMode.AutoSmooth);

I’ve tried various things for the tension parameter in GetAutoSmoothKnot.

That’s exactly the problem I am facing when trying to split a spline.
Is there any good option to insert a new knot seamlessly?

Hi! Different, but maybe helpful - if you are inserting a point that shouldn’t change the Spline curve, eg you just need it for data (checkpoint on your race track, spot where the road changes width, etc), you would be better off using a Data Point (vs a Spline Point aka Knot).

Data Points are specifically designed for this scenario - you want data at a point along the spline, but you don’t want to affect the shape. Tada! :slight_smile:

3 Likes

How to Transition Unity Spline Features from Editor Mode to Runtime?
I am currently using Unity Spline and can edit spline nodes in the Scene view during Editor mode. However, I would like to generate and control splines at runtime in the Game view.

Could anyone provide guidance on how to transition these features from Editor mode to Runtime? Detailed steps or example code would be greatly appreciated.

Specifically, my requirements are:

  • Dynamically generate splines when the game starts.
  • Control the position of spline nodes during runtime.

Thank you very much for your assistance!

You can simply create a spline and add knots to it. I’d recommend feeding chatGPT with the api if you need specific code examples (look at the spline constructors and bezier knots)

Definitely useful, but not for my particular case. I am splitting a spline so that each half may be manipulated independently, so I need a proper knot at the split point.

The docs seems to suggest that GetAutoSmoothKnot() is supposed to do that, but I haven’t gotten satisfactory results.
But if not, my goal should still be possible if I could calculate the required auto tangent tension such that the curvature is unchanged. How would I do that? I.e., how is ā€œtensionā€ related to the Bezier tangents?