Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Official Unity Splines

Discussion in 'World Building' started by gabrielw_unity, Oct 5, 2022.

  1. yarilo

    yarilo

    Joined:
    Dec 14, 2012
    Posts:
    5
    - Do you have an official source code for the spline package ( I found https://github.com/needle-mirror/com.unity.splines )?
    - Is there any way to play SplineAnimate in reverse order? I created a loop animation and my object moves counterclockwise by default. I suppose it depends on the order of knots created. Can I change it somehow?
     
    graskovi, Kamyker and shikhrr like this.
  2. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    661
    The first post in this thread shows a road following a spline.


    Was this done with the Splines Package? If so, how was this done? Spline extrude only makes tubes and spline instantiate doesn't bend objects. If not, can you please add this functionality? It is needed to make things like roads.
     
  3. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    526
    Agreed. In the next update we added a "quickstart" to the API landing page. In the meantime, I'd suggest importing the samples and referencing the SplineCommonAPI class for a substitute.

    In case you're still looking, the evaluation functions are in SplineUtility:
    https://docs.unity3d.com/Packages/c...tility_EvaluatePosition__1___0_System_Single_
     
  4. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    526
    The source code is not available in a public repo, but is included when you import the package. Right click the Splines folder in Unity and "Show in Finder/Explorer" to view.

    You can reverse a Spline in the editor using the Scene View "Knot Inspector" overlay.
     
    yarilo likes this.
  5. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    526
    This is an example scene included in the Samples, which can be imported from the Splines entry in the Package Manager window.
     
  6. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,474
  7. Acissathar

    Acissathar

    Joined:
    Jun 24, 2011
    Posts:
    650
    Hi,

    A few issues I have run into:

    1. Spline Animator doesn't show all fields (notably Movement related settings) until you deselect the game object and then reselect it.
    • Adding Component
      upload_2023-1-19_9-7-52.png
    • Deselecting and reselecting
      upload_2023-1-19_9-8-16.png

    2. Occasionally, selecting any Spline object causes a bunch of Look Rotation messages to spam the console as long as any spline object is selected. It seems to be random, and resets for a little upon restarting the Editor, but I have not been able to consistently replicate it, but it only occurs on Spline objects. The log itself also doesn't give much info about where it's coming from upload_2023-1-19_9-10-11.png

    3. Although you can select multiple objects with Spline Animators and the component doesn't give the usual Multi-Editing is not Allowed message, pressing Play for preview will only apply it to the most recently selected object. De-selecting an object will stop the Preview as well.

    4. Max Speed of 0 causes the time to recalc to NaN, but changing Max Speed to non-zero does not recalculate out of that. The time remains NaN until Restart is called. A workaround is to clamp to something like 0.001 I suppose and then Pause.
     
    Last edited: Jan 19, 2023
    Shizola likes this.
  8. Marcos-Elias

    Marcos-Elias

    Joined:
    Nov 1, 2014
    Posts:
    141
    Does it work with floating origin?
    Currently I’m using Dreamteck Splines, it uses local positions so we can move the entire spline and everything just continues working. I would like to confirm that before upgrading my projects.
     
  9. gabrielw_unity

    gabrielw_unity

    Unity Technologies

    Joined:
    Feb 19, 2018
    Posts:
    956
    If I understand correctly - yes. The Spline object can be moved anywhere, result will be the same as moving a parent gameobject - all the child objects stay with it.
     
    Marcos-Elias likes this.
  10. JonathanMeaney

    JonathanMeaney

    Unity Technologies

    Joined:
    Jan 28, 2022
    Posts:
    4
    We're tentatively scheduling a release for the end of February.
     
  11. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,474
    Any chance to get an early release for some people? Is there somewhere where one can contribute and give feedback before a release?
     
  12. Nblues

    Nblues

    Joined:
    Aug 26, 2014
    Posts:
    1
    Great job on the spline system! Its very nice to use and the spline painter is good!

    I have read through the documentation to see if there is a function to get the distance between two points on a spline (follwing the flow) but I cant seem to see any easy fix hehe. Am I missing something in the documentation or could someone maybe help point me in the right direction of how to find this? :)
     
  13. JonathanMeaney

    JonathanMeaney

    Unity Technologies

    Joined:
    Jan 28, 2022
    Posts:
    4
    For this release, there aren't plans for organizing anything like that. We really like sharing pre-release versions for feedback, but we're not set up for it right now.

    However, we do appreciate any documentation feedback you have at any time. You can always click the Report a problem on this page button to leave feedback on the documentation. We read it!
     
  14. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,474
    I figured, since I saw that you guys also added instant selection and dragging as I showed how I needed it in the other thread.

    However we based our asset on the Unity Splines. Really, really promising spline framework of yours. But if you guys release all of a sudden something that doesn't work properly anymore we are in a support hell with negative reviews.

    Some don't like beta-testing, I however do. It shapes the way. If you guys want early feedback and testing, I'm in :)
     
    gabrielw_unity likes this.
  15. chrpetry

    chrpetry

    Joined:
    Mar 7, 2018
    Posts:
    49
    First thing I did when using Splines package here is writing extensions...

    Can you please add convenience methods
    • Convert float3 to Vector3 (and back)
    • Get a list of Vector3 from Spline ("GetPositions()")
    • Spline.SetKnot(-1, ...) // -1 to fetch last knot
    And I guess I will stumble on many other stuff that would be nice to have.
     
    Last edited: Feb 3, 2023
    Novack likes this.
  16. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    102
    I was wondering why the spline.changed delegate has been deprecated and insted the static method UnityEditor.Splines.Spline.OnSplineChanged is implemented.
    Is there any advantage by using this workflow?
     
  17. ANFADEV

    ANFADEV

    Joined:
    May 27, 2016
    Posts:
    117
    I'm actually surprised it was just "changed", i would say they have corrected to Unity's common way of naming events.

    Maybe extension methods like float3.ToVector3() for cross conversion would be handy yeah
     
  18. Balours

    Balours

    Joined:
    Nov 27, 2013
    Posts:
    54
    How precise is the EvaluatePosition on the spline?
    I'm placing X objects on the curve based on the Length of it (example if length = 10, 10 objects, 1 at every unit), and I want them to move all together along the spline, but It's not accurate at all. Even when spawning I can see weird spacing between objects (in this example spline length = 120, with 120 objects):
    upload_2023-2-8_12-6-26.png

    Then if I try to move them using varioug methods it always end ups with inaccurate offset building over time.
    Is there a spline resolution somewhere? Or something else I should use instead of EvaluatePosition?
    Thanks!
     
  19. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    710
    float3 has an implicit conversion operator for Vector3, so a toVector3() method would be redundant.
     
    Novack likes this.
  20. ANFADEV

    ANFADEV

    Joined:
    May 27, 2016
    Posts:
    117
    As he said "methods", i thought he'd want his own extension method, else you'd only need a cast yeah, which is what i use, works well thanks

    Code (CSharp):
    1. (Vector3)myFloat3;
    2. (float3)myVector3;
     
    Last edited: Feb 9, 2023
  21. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    710
    Its implicit, so you don't need to cast,

    Code (CSharp):
    1. float3 myFloat3;
    2. Vector3 myVector = myFloat3;
    3.  
    You can pass float3 to all methods that take Vector3 as a parameter without casting. and it works both ways.

    Code (CSharp):
    1. float3 position = transform.position;
    2. // to some stuff
    3. transform.position = position;
     
    Novack and ANFADEV like this.
  22. ANFADEV

    ANFADEV

    Joined:
    May 27, 2016
    Posts:
    117
    You'll still need to cast when using some math operators the add implicit is missing for example
    e.g (my use case)
    Code (CSharp):
    1. myVar += (Vector3)MySpline.EvaluatePosition(0.5f);
     
    Novack likes this.
  23. ANFADEV

    ANFADEV

    Joined:
    May 27, 2016
    Posts:
    117
    @gabrielw_unity @JonathanMeaney
    About the API, can we discuss the way some values are returned?
    Maybe there could be a better way...

    Currently using GetNearestPoint() requires 2 out parameters + gives a return value
    A better way for me to do this is returning the values in a struct
    for example:
    Code (CSharp):
    1. public struct NearestPointData {
    2.     float Distance;
    3.     float Ratio;
    4.     float3 Point;
    5. }
    Also by declaring the function as an extention method (clutter is a way lesser problem, other Unity classes have way more already without it being a problem)
    So the thing would go as:
    Code (CSharp):
    1. // from
    2. myDistance = SplineUtility.GetNearestPoint(mySpline, transform.position, out myPoint, out myRatio);
    3. // to
    4. myPointData = mySpline.GetNearestPoint(transform.position);
    this way we can retrieve one of the values inline, without needing a bunch of variables....
    Code (CSharp):
    1. // Currently this can't be done as strightforwardly as this!
    2. transform.LookAt(mySpline.GetNearestPoint(transform.position).Point);
    Edit: also the "out float3" is not easily interchangeable with a vector3, which makes for a greater overall pain
    Edit2: the method doesn't accept
    SplineContainer
    , doesn't really work with a
    Spline
    , only works by using
    NativeSpline
    dunno why use generic type then
     
    Last edited: Feb 12, 2023
    graskovi likes this.
  24. Balours

    Balours

    Joined:
    Nov 27, 2013
    Posts:
    54
    Any chance to have informations on that? Just so I know if I wait for an update or move onto another spline system.
     
  25. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,585
    Can unity spline methods be called from Jobs?
     
  26. osgseb

    osgseb

    Joined:
    Jan 17, 2022
    Posts:
    12
    Hello,

    I just tried the package and take a look at the extrude example but it seems that it's hard-coded and can only extrude a tube and not any kind of mesh. Is there plan to create a more generalized version of this script ? It could be very useful in many scenarios, like create roads from a prefab.

    Taking example from the Sprite Shape Controller it could be very cool to be able to specify different meshes depending to the curvature of the spline in order to have more control of the result.

    Anyway, the package it's cool and I'm looking forward to see what else is coming.

    Good job.
     
  27. unity_8p6oRXXqiWbRTQ

    unity_8p6oRXXqiWbRTQ

    Joined:
    Dec 20, 2018
    Posts:
    18
    This would be such a basic needed tool, i cant stress enough how important this would be. There is a free spline tool in the unity asset store, called spline mesh, which sadly isnt updated anymore, but maybe could be used as an inspiration.
     
  28. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    252
    Hi @gabrielw_unity - I've noticed that SplineUtility.GetPointAtLinearDistance returns based on the scale of the spline - e.g. if the spline gameobject is scaled to 2 and you ask for a point 1 unit away, it will return a point 2 units away. Is this expected behaviour? It's easy enough to work around at uniform scalings, but a bit tricker if the scale is non-uniform.

    Edit: this is my current hack, but it relies on the forward vector of the previous point, so I guess it's not completely accurate -

    Code (CSharp):
    1. float localSpaceDistance = transform.InverseTransformVector(currentForwardVector.normalized * distance).magnitude * Mathf.Sign((distance));
     
    Last edited: Feb 27, 2023
  29. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    679
    I'm using 2021 lts. Can't find official github for Splines. Should i install 2022, download via package manager and copypaste to 2021 project, or is there some easier way?

    edit: i guess this is the closest one for official: https://github.com/needle-mirror/com.unity.splines
     
    Last edited: Mar 3, 2023
  30. JonathanMeaney

    JonathanMeaney

    Unity Technologies

    Joined:
    Jan 28, 2022
    Posts:
    4
    Hey!

    Splines is compatible with 2021.3, but not supported. In 2021,3, you can find it in the Package Manager if you search for the package by name:
    1. In the Package Manager, click the + sign dropdown and select Add package by name...
    2. In the Name field, enter com.unity.splines.

    upload_2023-3-3_10-11-21.gif
     
    chelnok likes this.
  31. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    526
    Yes, in fact there are some evaluation jobs included in the `SplineJobs` class.

    On the question of overloads vs. out params, we did it this way because it's very common to check if a point is closer than x to a spline, then do something with the out parameters. It's a matter of preference, and there certainly is merit to an alternative that would return a struct with a data payload.

    On out float3 not working with out Vector3, yeah that's an annoyance for sure. Unfortunately I think we're stuck on this one unless we move all our math to UnityEngine. Being inconsistent between float3 and vector3 would be significantly more annoying in my opinion.

    What doesn't work when passing `Spline`?

    GetPointAtLinearDistance doesn't apply any transformations. I'd need to see the full code to see where the scale is being introduced.
     
  32. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,474
    @kaarrrllll is there an ETA for the next spline update? I thought end of Feb, but there's nothing yet. Just asking if I should continue with current version or still wait for next
     
  33. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    526
    I don't have an exact date, but I can tell you that we have a last few PRs in review before release QA starts. From that point, probably another week or two before the updates are published to the public repo.
     
  34. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,474
    Nice, thanks. I know it's hardly an option, but if you guys need some testing or feedback before you roll it out to the masses, just hit me up. Or I guess @JasonBooth as well, since his asset is one which uses your splines extensively and it's an excellent showcase.
     
  35. ANFADEV

    ANFADEV

    Joined:
    May 27, 2016
    Posts:
    117
    In the end, because of my use cases i had to implement extension methods in order to avoid, having to declare stale variables, cluttering the code, and avoid the out float3 problem

    I don't really know the returned values were completely wrong, couldn't use them either in local or world space
    So i ended up passing the spline's transform and manually using a NativeSpline like this:

    Code (CSharp):
    1. public struct NearestPointData {
    2.     public float Distance;
    3.     public float Ratio;
    4.     public float3 Point;
    5. }
    6.  
    7. public static class SplineExtensions {
    8.  
    9.     public static NearestPointData GetNearestPoint(this NativeSpline nSpline, Vector3 position) {
    10.         NearestPointData data = new();
    11.         data.Distance = SplineUtility.GetNearestPoint(nSpline, position, out data.Point, out data.Ratio);
    12.         return data;
    13.     }
    14.  
    15.     public static NearestPointData GetNearestPoint(this Spline spline, Transform splineTransform, Vector3 position) {
    16.         return GetNearestPoint(
    17.             new NativeSpline(spline, splineTransform.localToWorldMatrix), position
    18.         );
    19.     }
    20. }
    And doing the same for SplineContainer


    I also had a few more points to raise:

    1) Could we get a getLength() function that takes as params start and end indexes, in order to measure between two knots? it's not really complicated i did it again with extension methods, just thinking it would benefit the rest

    2) I noticed the spline change event field is "global" meaning not per-spline, is it this way for performance reasons or something else?

    3) Having had to update my spline-based scripts when a knot is removed/added, i found out that the "knot removed event" does not return the removed knot and curve, in its parameter.
    Can this be resolved? because without those values that event is pretty much useless,
    In my use case i had to cache the knot in a private variable, at Start(), Update() and after any spline change,
    Just so that i can use the removed knot's value to update my system.
     
    Last edited: Mar 7, 2023
    osgseb likes this.
  36. skowronski_m

    skowronski_m

    Joined:
    Oct 5, 2021
    Posts:
    37
    Hello, and first all of thank you for the amazing spline package. However, I stumbled upon an issue with the UVs if I extrude the spline. I would expect the uvs to span the entire extruded spline, but if you consider the below spline, where
    if(uv.y =1) col.rgb = float4(1,1,1,1);
    , you see that the uv space is restricted between the first and second knot of the spline.



    Do you have any suggestions or timeline on how to fix this?
     
  37. Image3d

    Image3d

    Joined:
    Jun 20, 2008
    Posts:
    150
    How can I attach a Knot to an GameObject, so when this GameObject moves the knot also move ?