Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Official Unity Splines

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

  1. duzbot

    duzbot

    Joined:
    Aug 31, 2017
    Posts:
    17
    So you can add components to Game Objects that you select in a Spline Instantiate component - i.e. rigid bodies, which makes sense, of course. However, adding a Spline Animate component doesn't seem to work correctly.

    I played with some of the properties in the corresponding Spine Instantiate component and managed to get some additional instantiate items with the Spline Animate component to appear and animate around the spline, but they behaved erractically and were not usable.

    EDIT:
    It turns out that the Spline Animate objects are being instantiated, just that they are in the same position so are appearing as one single object. What I was hoping for was that Instantiate objects would begin animating from their individual start position, whereas they are all snapping to one start point (which doesn't appear to be controllable?)

    The use case for all this is something like a train on a track, where you can use the instantiate properties to generate a train with different carriages, and then have all the train carriages move together via the Spline Animate component
     
    Last edited: Jul 5, 2023
    ThomasLopez likes this.
  2. taimex

    taimex

    Joined:
    Feb 20, 2022
    Posts:
    13
    I've chosen to switch to Unity Splines over two other Assets I've purchased and developed with because of your methods for handling Spline Data. But I have found two issues that I'd like to bring up:

    1) In the Inspector, when we have specified Default Value(s), they are not being used when we add a new DataPoint with the (+) button. This is true for Int, Float, Float4, and Object Data. It occurs if you already have some DataPoints created or adding when the first one to the list.

    2) When calling SplineData<>.Evaluate(), and have yet to create any DataPoints, the DefaultValue is also ignored. The code at SplineData:428 calls the compiler generated 'default' method. This does not use the DefaultValues.​

    I believe in both cases, you should use the DefaultValues specified in the Inspector. It seems like its purpose by name and Inspector use and would be very helpful. Because you do not do this, every place we want to evaluate spline data we must first manually check for an empty list of data points and if true, substitute in those DefaultValues on our own. I can't think of cases where I'd prefer the compiler 'default' (which is zero's) to be used. Since, an unmodified (default value) of DefaultValue is zero, the affect would be the same in those use cases anyway.

    If I create a new Data element by creating a Key and Default Value entry, why would I NOT want my values to be use and returned even when I have not created a DataPoints? For example IntData for a 'road width'. I don't want a default to 0, I want a default to what I put into 'road width' when I created the Key.

    Else we must do this everywhere:
    Code (CSharp):
    1.  
    2. int roadWidth = widths.Count == 0 ? widths.DefaultValue : widths.Evaluate( splineContainer.Spline, t, PathIndexUnit.Normalized, new RoadWidthInterpolator() );
    3.  

    My suggestion is more generally useful than reserving DefaultValue's use only for the AddDataPointWithDefaultValue method as it seems now.
     
    Last edited: Jul 9, 2023
  3. duzbot

    duzbot

    Joined:
    Aug 31, 2017
    Posts:
    17
    I recall a similar issue I had with ProBuilder - I think it is to do with the way Unity serialises data fom the editor and isn't specific to Unity Splines.
     
    Unifikation likes this.
  4. taimex

    taimex

    Joined:
    Feb 20, 2022
    Posts:
    13
    I don't think this is the whole issue because in at least two cases, the code is specifically calling 'default' when the size is 0. They could instead use the DefaultValue methods instead.
     
  5. m0nkeybl1tz

    m0nkeybl1tz

    Joined:
    Feb 10, 2013
    Posts:
    35
    Hey sorry if this is obvious but is there any way to get a list of all the instances a spline created? My thought was for a traffic system, it would be useful to know where the instance in front of you is without needing to raycast etc
     
    ThomasLopez likes this.
  6. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    534
    Hi
    The Spline.Changed and EditorSplineUtility.AfterSplineWasModified events are not triggered when a spline changes due to knots linking. I created an incident with more details. Incident number IN-48215
    Thanks
     
    ThomasLopez likes this.
  7. backwheelbates

    backwheelbates

    Joined:
    Jan 14, 2014
    Posts:
    231
    Hi, Ive seen some discussion about this before but not yet answered.

    I have built a spline by code(Auto Tangent, Catmul Rom), the first and last tangents are oriented incorrectly. As soon as I move one of ends with the spline move knot tool, there is something under the hood that corrects the tangents. Does anyone know how or what the edit tool does this correction? Is this a function that I can access? Thanks!

    gif_2023-07-24 03-39-24 PM.gif
     
  8. Pitou22

    Pitou22

    Joined:
    Sep 23, 2015
    Posts:
    47
    Hi, first of all, a big thank you for this package!

    Just a small feedback:
    In the editor, the component "SplineContainer" is displayed as "Spline"
    upload_2023-7-27_23-38-34.png
    But of course, in the code, you can't
    GetComponent<Spline>()
    and should
    GetComponent<SplineContainer>()
    .

    Why are you displaying a name that is not the name of the component and introduce confusion?
    Displaying it a a proper SplineContainer will also emphasize the fact a SplineContainer can contains multiples Splines.
     
    ThomasLopez likes this.
  9. Shindluder

    Shindluder

    Joined:
    Jan 19, 2021
    Posts:
    3
    I just started reading about the Splines and i am more confused than before. Anyway, i just wanted to say, what you ask was already a question on the first page of this thread... I understand that Unity wants to make their stuff as universal as possible, but seriously, some love to the product and user friendly moves would help a lot...
     
  10. fwalker

    fwalker

    Joined:
    Feb 5, 2013
    Posts:
    255
    I want to change the knots on a spline and regenerate the instantiated objects in real-time, in code. I am able to change the knots, but I can't figure out how to regenerate the instantiated objects along the spline. Can someone give me a hint pretty please?
    Note: I instantiated the original set of objects with the Spline Instantiate component.
     
  11. freyzorr

    freyzorr

    Joined:
    Jul 26, 2015
    Posts:
    29
    If your using the SplineInstantiate component it has a public UpdateInstances method you can call.
     
    ThomasLopez likes this.
  12. enemali

    enemali

    Joined:
    May 29, 2017
    Posts:
    18
    i want to increase and decrease the spline extrusion RANGE via script , any sample script please
     
  13. freyzorr

    freyzorr

    Joined:
    Jul 26, 2015
    Posts:
    29
    There is a public Range property to set the range and then a public Rebuild method to regenerate the mesh. There is already a sample in the spline examples (2.2.3) AnimateSplineExtrude that does exactly this. You can also call a SplineMesh.Extrude yourself, used internally by SplineExtrude during rebuild.
    Code (CSharp):
    1. var extrude = GetComponent<SplineExtrude>();
    2. extrude.Range = new Vector2(0.25f, 0.75f);
    3. extrude.Rebuild();
     
    ThomasLopez and enemali like this.
  14. batteryyrettab

    batteryyrettab

    Joined:
    Sep 20, 2013
    Posts:
    7
    Firstly, I am enjoying using the Spline package. I was keen on it as soon as it was first displayed. But I still have issues wrangling it for various use cases.

    The basic things it does very well, and the UI integration is very smooth. The spline instantiating is amazing. However, working with the code... That's causing me issues.

    Here's one...

    Trying to get easy spline switching happening. General concept is to have a track that splits and the user can control going left or right.

    I have something like this working well with Cinemachine paths and a Dolly Cart:
    • trigger zone near end of single path;
    • that has two paths that split off it,
    • script has reference to two different paths,
    • enum with left or right path as choice
    • reverse occurs later (two paths meet, a single path is the only choice)
    Just thought I might see if I could use a single Spline (really a SplineContainer - that also confused me early on) to achieve the same thing. Otherwise, it gets clunky having to do several SplineContainers. Also, frustratingly, it defaults any actual splines created to the first instance of a SplineContainer on the Gameobject, so now you also need different parent objects each with a SplineContainer on it.

    I think having easier access to Knot information could make this a bit easier than the very manual way done in the HighwayExample.cs script. Actually, access to a number of fields that are locked down, would be great.

    See attached images for what my concerns are in this issue.
    • Image ending with p0 - low-res working version with Cinemachine Paths and Dolly Cart,
    • Image with p1 end - shows Unity Editor can easily display Knot Indices,
    • Image with p2 end - showing I can inspect information - I just can't figure out how to get them easily for use in Editor. I don't want to modify linked knots. I just want to show the user/developer the main junctions.
    Get Knot Indices p0.png

    Get Knot Indices p1.png

    Get Knot Indices p2.png

    My main issue seems to be access to things that, for some reason, are not easily accessible.

    e.g. in the KnotLinkCollection the KnotLink data. This could help show which knots, on which splines, are linked. Dynamic triggers could be added near these points for a player to control which spline to switch to. Comments added for items that seem useful for my purposes.

    Code (CSharp):
    1.     public sealed class KnotLinkCollection
    2.     {
    3.         [Serializable]
    4.         /*Could this be more easier to access? */ sealed class KnotLink : IReadOnlyList<SplineKnotIndex>
    5.         {
    6.             public SplineKnotIndex[] Knots;
    7.  
    8.             public IEnumerator<SplineKnotIndex> GetEnumerator() => ((IEnumerable<SplineKnotIndex>)Knots).GetEnumerator();
    9.  
    10.             IEnumerator IEnumerable.GetEnumerator() => Knots.GetEnumerator();
    11.  
    12.             public int Count => Knots.Length;
    13.  
    14.             public SplineKnotIndex this[int index] => Knots[index];
    15.         }
    16.  
    17.         [SerializeField]
    18.        /*Could this be more easier to access? */ KnotLink[] m_KnotsLink = new KnotLink[0];
    Sample code below is that shown in image ending in p2 - early trials at trying to access linked knot information. At present I am tending to think I'll stay with the more rudimentary CinemachinePaths until things get easier to work with. Splines are amazing to create, the UI is very well integrated and smooth, and far superior to clunky gizmo waypoints of CinemachinePaths. But the Spline API is frustrating me.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. using UnityEngine.Splines;
    6.  
    7. /// <summary>
    8. /// Trying to get basic spline 'track' switching working.
    9. /// Ideally the user, like in an on-rails game, could in-game choose left or right track
    10. /// </summary>
    11. public class CustomSplineNavigation : MonoBehaviour
    12. {
    13.     [SerializeField] SplineContainer splineContainer;
    14.     [SerializeField] private IReadOnlyList<Spline> allSplines;
    15.  
    16.     [SerializeField]
    17.     List<SplineKnotIndex> KnotsWithLinks = new List<SplineKnotIndex>();
    18.  
    19.     IReadOnlyList<SplineKnotIndex> linked;
    20.  
    21.     // Start is called before the first frame update
    22.     void Start()
    23.     {
    24.         allSplines = splineContainer.Splines;
    25.  
    26.         // Knot connections are stored in the KnotLinkConnection type
    27.         var links = splineContainer.KnotLinkCollection;
    28.  
    29.         for (int i = 0; i < splineContainer.Splines.Count; i++)
    30.         {
    31.             var totalCount = splineContainer.Splines[i].Count;
    32.  
    33.             for (int j = 0; j < totalCount; j++)
    34.             {
    35.                 var knotIndex = new SplineKnotIndex(i, j);
    36.                 if (links.TryGetKnotLinks(knotIndex, out linked))
    37.                 {
    38.                     Debug.Log($"Spline {i} at knot {j} have found {linked.Count} connected knots!");
    39.                     KnotsWithLinks.Add(knotIndex);
    40.                 }
    41.  
    42.             }
    43.         }
    44.  
    45.         // splineContainer.Spline.m_Knots.Array.data[2].Position
    46.     }
    47. }
    48.  
    I hope I have been clear enough - apologies if I haven't. Maybe I'm missing something, maybe I've overlooked something very basic. Any help would be great.
     
  15. Dried09

    Dried09

    Joined:
    Jan 2, 2017
    Posts:
    7
    Hi All,
    Any ideas in what direction to go to achieve spline visualization, particularly partial (like progress bar)?
    Perfectly it could be something like drawing line along spline or even better something that works for UI in canvas.
    But any ideas is highly appreciated.
    Thanks
     
    ThomasLopez likes this.
  16. fwalker

    fwalker

    Joined:
    Feb 5, 2013
    Posts:
    255
    Is there any way to set the tangent (in/out) length instead of the position through script? Musch Like it works on the editor?
     
  17. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    SplineInstantiate.cs is laggy as all hell, if you try and select a Static / Lightmapped gameobject in the scene.

    If you run into this I have found that there is some sort of bug with if a gameobject is set to HideAndDontSave that makes Unity 2021.3.29 LTS lag like crazy. I don't know about other versions. Gonna file a bug i guess...

    Repro:
    1. make a lightmapped scene.
    2. use SplineInstantiate.cs.
    3. click one of the lightmapped gameobjects.
    4. lag central
     
  18. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,097
    Is there a utility method to check if one spline crosses with another? Or how do you "un-knot" overlapping splines?
     
    Last edited: Aug 10, 2023
    fwalker likes this.
  19. freyzorr

    freyzorr

    Joined:
    Jul 26, 2015
    Posts:
    29
    Is there some method of generating offset curves from Unity Splines? The specific use case I have in mind is a generated river/road surface. The naïve approach of just building quads/triangles at intervals of t of some width runs into problems when the inverse curvature of a spline becomes less than the width of the spline. Then the quads of the inside of the bend will become degenerate as the perpendicular lines at t and t+1 will start to intersect each other.

    creating offset lines on each side of a spline and then use that to generate the ribbon would solve that. Which begs the question, how do you create an offset spline curve using Unity Splines?
     
    ThomasLopez likes this.
  20. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    278
    Hello Spline team, I try to make a river spline as soon as I see spline has branching feature. But the lack of knot scaling still holds back the idea. Do we have it in the road map?
     
  21. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    278
    Also for river shader to adopt this mesh, the part where branches split should be continuous.
    upload_2023-8-14_13-20-59.png

    mesh not continuous will has this artifact when applied water shader.
    upload_2023-8-14_13-46-5.png
     
    UnityFledgling and freyzorr like this.
  22. UnityFledgling

    UnityFledgling

    Joined:
    Jan 30, 2022
    Posts:
    20
    Question: Is it possible to create a shape in Unity and have that shape be extruded procedurally along a proceduarally animated spline? Like a tube that sways underwater.
     
  23. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hey @sand_lantern!
    Sorry for the (long) delay!

    So this does sounds like a bug, we recently released splines 2.4.0 so I'll check if that it's still a thing or if it has been fixed since your post.
    Can you just give me a little more context on your case?
    Did you create the spline using the in-scene tools, or via code?
    What is used for the knots tangent modes (auto, bezier, broken)?

    Thanks!

     
  24. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hi @voodooRod.
    Indeed, this is just a small amount but not desired.
    We will have a look at this!

     
  25. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    So about that, we got the ticket but I need to give an extra context on that.
    Spline knots can be linked through the SplineContainer (which contains a list of splines) and not at the Spline level itself. regarding that, links between knots are only possible between splines belonging to the same container.
    This means that a Spline does not know if its knots are link to other spline knots and should not be aware of that because this does not influence the spline itself.

    As Spline.Changed and EditorSplineUtility.AfterSplineWasModified are triggered at the Spline level these events cannot be raised when the links between knots are modified, hence the current behavior.
     
  26. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hi there!
    Did you have a look at the SplineExtrude component and its sample?
    You can call the Rebuild() method on it when you want to refresh the mesh and also set it to RebuildOnSplineChange. I think that should do the effect you want, let me know if not!

     
    UnityFledgling likes this.
  27. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    @freyzorr,

    First, thank you for your answers to other Splines users on the forum regarding the use of the components!

    Regarding this usecase, indeed offsetting a spline can be complicated. So teh API does not provide and solution for that and this has to be done by the users. If you look at our LoftRoad sample we have the same issue when generating the road mesh.

    On a personal side, I did try to look at that a while ago, if I remember correct, a solution I found was to scale the knots tangents regarding the curvature at the current position (basically scale up the tangent when outside of the curve, scale it down when inside), this relies on the curve at that point and the direction of the offset. However as I said, we do not provide this, this would require to be coded by the user I think as there is no plan to add this to the current API.

     
  28. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hey hey!
    Can you give me a little more context on the reason you would need knot scaling?
    I think what you are looking for can be achieved using our SplineData system.
    We are demonstrating that in a sample where we generate a road with different width along the way:

    upload_2023-8-21_12-4-37.png

     
    Spikebor likes this.
  29. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    So yes, for your usecase the linked knots should have similiare tangents out so taht the rivers start in the same direction before splitting. However in some other cases, such as road cross for instance, or a bridge going over your river but connected to it so that the passage is always at the same position, this is not a desired behavior. This is why we didn't make it happened.

    This is a specific behavior that would require to be coded on your end, but this should be as simple as setting the tangents to Bezier and copy the tangent out value of the desired knot to the other knot linked to it.

    Hope this helps :)

    Also, another solution could be to create SplinePath with the different river flow and update the tangents out values using the same process I just explained.

     
    Spikebor likes this.
  30. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hi @Rowlan,

    We do have a Utility method to compute a distance between a point or ray and a spline. However, we do not have a utility method to check if splines are crossing.

    Regarding your second quesiton, I'm not certain I get what you mean by "un-knot", could you detail that a little more?
    Thanks!

     
  31. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hi @sameng,

    Can you tell me which was the version of the Splines package you used?
    I know we did some changes recently on SplineInstantiate related to HideAndDontSave flag and lightmap static objects, so I'm curious if this was before and/or after the changes.
    Thanks

     
  32. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    @fwalker,

    So just to clarify a thing, the way it's working in the editor is that the position of the tangent is changed, even thought it feels and look like the length is the only thing changing :) So we are happy you feel that way as this was the desired effect, simplify the manipulation!

    To answer the question now. The solution should be only to get the current tangent you want to modify in the code, normalize it and then multiple the result by the length you want and set this value as the new one. You don't need to know the actual position, this position is actually local to the knot orientation, you only need to scale it.

    Hope this explanation is clear enough.


     
    fwalker likes this.
  33. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    278
    Thanks for the answers Thomas, I've overlooked the example with scaling, my bad. It is because when I scale with the Scale Tool, I expect the width will change, but instead it scales the Bezier.
     
  34. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    HI @Dried09,

    Did you take a look at our Paint Splines sample?
    We are taking the users input in playmode to build a spline and feed that in a UI Document.
    Would that help you ?



     

    Attached Files:

  35. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    @Spikebor, yes, the scale tool is used to scale the knots themselves, so their tangents.
    The spline is used to build the mesh around but the "width" of this mesh is a parameter related to the mesh and not the spline itself, so spline tool won't affect it indeed :D

     
    Spikebor likes this.
  36. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Indeed,
    Thanks for the feedback.
    This is something we could improve a little as this seems to bring more confusion than needed! :)

     
    Pitou22 likes this.
  37. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hi @backwheelbates,

    Thanks for the feedback on that!
    It does look like a bug from what I saw where the first and last knot are using default rotations as there is no knot before/after.

    I'll log that on our side to check and fix, please let me know if you have a piece of code for the repro :)

     
  38. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hi @m0nkeybl1tz ,

    So it's not possible to access to a list of the created instances out of the box.
    Reason for that is that this instances are generated procedurally and handled by the component itself. Making such a list accessible would create some possibility to modify it and then potentially break the component more easily :eek:

    So here are 2 solutions I can see:
    - Once you don't need the SplineInstantiate component you can bake the instances in the scene (there is an option on the component for that since 2.3.0) but that will remove the component as well from the GameObject.
    - Another more valid solution would be to build that list of instances on your own side. For instance, add a manager in your scene with an Action/Event to register to that manager. Then make each instance you spawn (using SplineInstantiate) have a script that register to that Manager when they are enabled (and unregister when they are disabled), then do your work in your manager now you have all of the instances registered :D

     
  39. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hey @taimex,

    Thanks for the feedback on that!
    So the defaultValue used to be used when SplineData was not embedded in the SplineContainer but more on it's own component.
    However, now we have SplineData in the Container, that would be fair indeed to improve the use of the Default Values.

    Even though this could be simple (aytime a new data point is add set its value to the default one), we might also want other more complexe behaviors, could you give me your thoughts on these ?

    1. When a first data point is added, set it's value to default value
    2. When a data point is added between 2 others:
      2A / Use the default value
      2B/ Interpolate the value set before and after to keep the current interpolate and have a credible value at that position out of the box.
      2C/ Set the value to the same value than the previous (or next) data point
    3. When a SplineData is added before the first one (or after the last one):
      3A/ Use the default value
      3B/ Interpolate the value between the default one and the closest datapoint to insure a smooth interpolation
      3C/ Use the previous/next value of the next datapoint to this new one
    I'm curious to have your opinion on 2A/B/C and 3A/B/C :)

    Then, when interpolating the SplineData values, you would like that splineData.Evaluate(...) to return Default Value for t = 0 and t = 1 (using a normalized value for t), am I correct?

    Also, just to be clear this Default Value would be used only at the DataPoint creation. What I mean is that, let's say you create 4 data points with the default value, and then change this value to another one, that will not affect the 4 data points you created before, only the ones you'll create after that. Otherwise that demands too much book keeping for that.

    Thanks!

     
  40. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hi @CogumeloSoft,

    So first of all, there is no stupid questions :)

    So the answer really depends on what your usecase is.
    I will go for the more common one I would say : You are using splines that are contained in a SplineContainer.

    In that case the Splines are interpreted in the local space. I mean that all the knots positions, rotations and tangents does not care about the transform associated to the SplineContainer component but only refers to the spline itself. That's why usually the first knot position will be (0,0,0) for instance.

    At this point, if you do
    spline.EvaluatePosition(t)
    you'll get the position in the local space.

    Then at the SplineContainer level, if you GameObject as a transform (scale, rotation or translation) and that you do :
    container.EvaluationPosition(spline[0], t)
    for instance, you'll get the position in world space, with the GameObject transform applied to the spline during the interpretation.

    You can also inteprete the position in world space on your own, using NativeSpline. The NativeSpline constructor can take a 4x4 transform Matrix to interprete your spline in the space you prefer. You can then do:
    using var nativeSpline = new NativeSpline(spline, transform.localToWorldMatrix);
    return SplineUtility.EvaluateTangent(nativeSpline, t);


    Hope this helps you to have a little more clarity!
    Please le me know if that didn't answer the question, feel free to ask for more explanations!

     
  41. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hi @duzbot

    To clarify a little the situation here, <SplineInstantiate> was originally design to spawn static instances of objects in the scene, for instance trees or fences but not with the idea to animate them after.
    Using <SplineAnimate> is possible as you did but with some issues indeed. You can indeed control the start point along a spline using the startOffset parameter. However it becomes tricky when you want to couple that with a dynamically spawned instance as this requires to know where the element is placed along the spline! Which is not possible with the current components as they are.

    Regarding your train usecase, I will try to make it a little simpler:
    - Only spawn and animate the first wagon on the spline and animate it using Spline Animate
    - Other wagons are spawns behind the previous using the appropriate distance and to insure the spacing between each carriage, use the follow utility method :
    public static float3 GetPointAtLinearDistance<T>(this T spline, float fromT, float relativeDistance, out float resultPointT)

    This will insure that the distance computed are linear and not along the spline. Use this utility to compute from the head of the wagon where on the spline the end of the wagon is depending on its length and spawn the next one at this place.
    Then on update each wagon update should trigger the update of its follower :)
    Then all the settings for the speed, start and go only have to be set on the SplineAnimate attached to the head wagons and all the rest should follow and adapt correctly their position thanks to GetPointAtLinearDistance :)

    Let me know your thoughts on that!


     
  42. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hey @udede,
    Can you be a little more specific about what you mean by "always move in the direction I choose"?

    Usually prefab instances created using SplineInstantiate are more static instances that will not move after, it was designed more for procedural creation rahter than animation. It is however possible, I already answered some post on this, my previous post is also on this :)

    Feel free to give more information on your case and what you want to achieve.

     
  43. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hi @MirzaBeig,

    Sorry for the delay, catching up on the posts here :)

    Thanks a lot for your feedbacks on the package first and I'm glad you can try it out now :)
    So regarding our SplineExtrude component, we kept it simple for now. It could do a lot more but we didn't want it to be overcomplicated (for instance generate a squared pipe instead of a circle, but then, would someone need triangles? ;)) great Pandora box!

    So coming back to our problem here, UVs are based on the spline length indeed for that component. The reason is the same, to keep it simple :D another simple choice could have been what you proposed indeed, used the normalized value instead. Depending on the use case one or the other can be used indeed.

    So the Spline Length can be computed once and stored in a parameter for the shader indeed. Either using
    myComponent.ComputeLength(...)
    or directly
    spline.GetLength()


    If really needed, we could add a toggle maybe in the SplineExtrude inspector to change the UV generation to be either normalized or distance-based. What do you think about this, would that make sense to you?

    Thanks, (still catching up on your others posts, I'll reply next to them :D)


     
  44. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    Hi again,

    This is an original one.
    Can you give me more information on the repro steps here?
    I cannot repro that on my side...

    - What are you duplicating? The SplineContainer, the Spline in the SplineContainer or the SplineExtrude component?
    - How do you link the Splines and the SplineExtrude?

    So, usually to simplify the generation, I would tend to advice to have the SplineContainer and the SplineExtrude component on the same GameObject, this avoid to have offsets between the gameobjects, resulting in offset between the spline and the extruded mesh. But this does not seem to be the case here and an update refresh it correctly, so we are probably missing a quick update somewhere when duplicating :)

     
  45. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    I actually just repro-ed it, will log that bug :) Thanks!

     
    MirzaBeig likes this.
  46. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    @Unifikation,
    Thanks for your input but I think that's not really in the scope of this component.

    The component only provides unique copies.
    However if you want to do animations that animates multiple at the same time it's pretty simple, just create a bunch of other gameobjects with a MeshFilter pointing at the same mesh asset! Just modifying once the SplineExtrude settings will modifies all the other objects using the mesh itself.

     
  47. bleppie2

    bleppie2

    Joined:
    Mar 25, 2015
    Posts:
    6
    ThomasLopez and Lars-Steenhoff like this.
  48. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,097
    I meant when the splines cross if there is an option to modify the splines (contraction, relaxation, other algorithms) so that they won't cross. But that's network theory, and not part of the spline framework i guess.
     
    ThomasLopez likes this.
  49. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    534
    Thanks for the answer.

    I understand that links are represented at the container level, and splines don't need t know about them. But unlike what you said, the action of creating a link do modify the spline. You can see it in the video bellow, which is also attached to ticket IN-48215.

    The spline is modified. It does not need to know it was modified due to linking, but it knows it was modified, right? So in this case, the Spline.Changed event needs to be triggered, right?

    At the end of the day, I just need a way to know when a spline was modified, regardless of who/what modified it. This is my primary concern. Whether it is via Spline.Changed or some other event, this is secondary.

    Thanks for your time
     

    Attached Files:

    ThomasLopez likes this.
  50. ThomasLopez

    ThomasLopez

    Unity Technologies

    Joined:
    Jun 8, 2020
    Posts:
    159
    @Rowlan,
    Thanks for the clarification and yes indeed that is not part of this package as depending on the usecases (roads, rivers...) you might want this splines to cross :D

     
    Rowlan likes this.