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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

SplineMesh, the plugin to create curved content

Discussion in 'Assets and Asset Store' started by methusalah999, Dec 14, 2017.

  1. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    To get the curve index after the foreach, you will have to use a secret black magic function
    spline.curves.IndexOf(curve)
    . So much to learn ^^
     
  2. Bogaland

    Bogaland

    Joined:
    Feb 19, 2017
    Posts:
    32
    Which version of Unity works best for this asset? I tried it with 2017.1.1f1 and I get these errors when I open the showcase (from a clean project):
     

    Attached Files:

  3. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    SplineMesh is best used with the latest version of Unity. But I also test it with all these versions before any release:
    - 5.6
    - 2017.4 LTS
    - 2018.4 LTS

    I will check that. It seems to be a prefab issue into the showcase and you should be able to use SplineMesh with 2017.1.1 anyway.

    Please come back if you need any assistance.
     
  4. Bogaland

    Bogaland

    Joined:
    Feb 19, 2017
    Posts:
    32
    Looks like I had to drag the prefabs into the inspector again. So the Follower works (attached the cylinder), and I attached the rope prefab to the second one. There are no more errors, but nothing happens with the rope. I can see an animation in the scene view, but nothing in the game view.

    I'm also wondering what the best way to edit a track, like the road with railings, is? I tried to drag the nodes with alt but when I drag the last node I add a node behind it and drag the road in all kind of weird places. What is the best way to create a road with the loop as in the example? Do I need to manually enter the values for the nodes to get it to loop etc, or can I do it with dragging/rotating?

    Sorry for breaking your code :(
     
  5. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    Don't worry about the code, it's robust ^^

    About the showcase
    I'ma glad you've been able to make things work again. I will have to fix this one for the next release.

    About the rope:
    The rope exemple will work only during the simulation, in play mode. If you can't see the rope mesh moving, but the colliders are moving correctly in the edit view, then you might be suffering a known bug of Unity. Please try and go in projects settings -> player -> uncheck batching and see if it resolves the problem. It's not a fix, just a workaround for diagnostic purpose.

    About the spline edition
    When you hold alt and drag a node, you insert a node after the selected one. The behavior you are experiencing is due to you dragging not the last node, but the first. So you insert a node between the first and the second. Try to expand your spline by the other end, you will find it more intuitive ^^

    If you need to create a road, please considering adding the SplineSmoother component. This script will adjust the nodes' direction for you and smooth the path. It is not always what you want but it may help at the beginning.

    If you need to make a looping or any other upside down or almost vertical spline, you will have to mess with the node up direction. The default up is the world up, so when you go upside down your road will still face the sky, and when you go vertical, you will have a gimbal lock problem. To resolve both these problems, you must specify the up yourself for each node, as SplineMesh can't guess which direction you want to face. In the Spline script, you will find a check box to draw the up handle, which is hidden by default, then you will be able to drag it in the correct direction. Alternatively, you can enter vector3 values of the up in the inspector.

    Hope it helps !
     
  6. Bogaland

    Bogaland

    Joined:
    Feb 19, 2017
    Posts:
    32
    This might actually be a Unity problem. I remember I've had it before when trying to share scenes with others. For some objects attached in the inspector will be removed. Perhaps this could be fixed using code, forcing the objects into the inspector.

    By this you mean Edit --> Project Settings --> Player --> Other Settings --> Dynamic Batching? I unchecked it but nothing changes. I tried both on 2017 and 2019. It doesn't really matter much to me since I'm not interested in using those functions, but probably worth mentioning if you want to keep investigating.

    Ah yes, that solved it. I am able to extend the splines now. I thought I tried on both ends, but apparently not... :)

    The up vector is definitely helpful. Is that the only way to do it (unless I write something myself), to change each node separately? I'm trying to make a track of sorts, similar to this:



    Did you create that node by node? Or is there a way to rotate parts etc more easily? Tilted turns are especially tricky, for me it always seems as the track wants to be flat when I create a new node. Like this:



    As you can see, the node with the up vector wants to go the other way. I managed a sort of tilted turn but not without having a flat section in-between. How would I avoid this?

    Thanks for all the help! :)
     
  7. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    The track has been made manually, yes, as SplineMesh does not produce spline path itself. The best it can do for you is smoothing the direction with the SplineSmoother script.

    Fact is SplineMesh is used in a very wide variety of situation, and there is no common way of drawing a spline. That said, you can of course write your own path generator.

    For example, you can have a script that will decide the up vector for you, depending on the curvature of a turning, or the angle of a slope. It may become tricky to automate every cases, though.

    I can't really see the problem on your screenshot. The selected node is rolling correctly according to the up vector that seems to be 45° to the horizon (hard to say in a single shot). It's often hard to set the up vector visually, and I often found it easier to set a global value via the inspector. Remember that the up vector will only affect the roll of the bent content around the tangent. That's why the handle turns around the node on a disk. Here you can select a (1;0;1) vector to ensure the road will be vertical, for exemple.
     
  8. Bogaland

    Bogaland

    Joined:
    Feb 19, 2017
    Posts:
    32
    Alright! I will play around with it a bit and try to make my own path generator. Adding SplineSmoother made it much smoother and removed the flat parts.

    I've been getting some more errors. Not sure if you have encountered it, but it happened when I tried to add a node using the "Add node after selected" button.
     

    Attached Files:

  9. niklaswetterberg

    niklaswetterberg

    Joined:
    Aug 1, 2019
    Posts:
    2
    Hi!

    I am new to Unity and game development and I have trouble generating an object along the spline. I want to create a long road with surrounding terrain and have created a short segment in Blender (with both the road and terrain) which I want to generate along the spline. However, I do not understand what I should do in order to succeed.

    I manage to get a cylinder to generate along the spline really smooth my using the "Spline Mesh Tiling" script, add the cylinder as Mesh for the script, and rotating it 90 degrees on the Y-axis. I wonder what I should do in order to be able to get my on objects (the road and terrain which I created in Blender) to follow the spline. I have tried both .dea, .fbx and .obj files (although I do not actually know what difference there is between them). I want to achieve something like the bridge in the SampleScene but with my own road.

    Could someone please help me with this? I have uploaded the blender file with the road segment and terrain which I want to create along the spline.
     

    Attached Files:

  10. Pekay12

    Pekay12

    Joined:
    Aug 19, 2019
    Posts:
    6
    Hey there!
    I'm using the example follow spline script to make a tram drive through my scene. Now everything seems to look fine when I hit play but after I build my scene, the trams are not moving anymore. Any idea what could be the issue here?
     
  11. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    Hi there,

    SplineMeshTiling is the correct way to go for the need you describes. Let's test things by using the first example in SplineMesh showcase:
    - export your mesh in fbx format,
    - place the fbx somewhere in your project Assets folder, Unity will import it,
    - locate your fbx into the "Project" windo in Unity, open it and locate the mesh that is inside.
    - drag this mesh into the SplineMeshTiling component, in place of the base cylinder.

    Now you should see your mesh bent along the spline, BUT:
    - your mesh may be too small, or to big, depending on export/import parameters. Play with the scale to check that in SplineMeshTiling
    - the rotation of your mesh can be different, and it will be bent along the wrong axis. You can set a rotation in SplineMeshTiling. It should be 90° on one axis.

    Tell me if it doesn't work, i'll try on my side.

    Hope it helps
     
  12. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    You are right, some code is ignore in the build:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2.             EditorApplication.update += EditorUpdate;
    3. #endif
    This is done this way so the object follows the spline even when the game is not running. It's not a best practice and I've made things this way only to get instant demonstration in the showcase, without even having to run the game.

    Remember that ExampleFollowSpline is only an example ^^

    Please try that:
    Code (CSharp):
    1. public class ExampleFollowSpline : MonoBehaviour {
    2.         private GameObject generated;
    3.         private Spline spline;
    4.         private float rate = 0;
    5.  
    6.         public GameObject Follower;
    7.         public float DurationInSecond;
    8.  
    9.         private void OnEnable() {
    10.             rate = 0;
    11.             string generatedName = "generated by " + GetType().Name;
    12.             var generatedTranform = transform.Find(generatedName);
    13.             generated = generatedTranform != null ? generatedTranform.gameObject : Instantiate(Follower, gameObject.transform);
    14.             generated.name = generatedName;
    15.  
    16.             spline = GetComponent<Spline>();
    17.         }
    18.  
    19.         void Update() {
    20.             rate += Time.deltaTime / DurationInSecond;
    21.             if (rate > spline.nodes.Count - 1) {
    22.                 rate -= spline.nodes.Count - 1;
    23.             }
    24.             PlaceFollower();
    25.         }
    26.  
    27.         private void PlaceFollower() {
    28.             if (generated != null) {
    29.                 CurveSample sample = spline.GetSample(rate);
    30.                 generated.transform.localPosition = sample.location;
    31.                 generated.transform.localRotation = sample.Rotation;
    32.             }
    33.         }
    34.     }
     
  13. jiraphatK

    jiraphatK

    Joined:
    Sep 29, 2018
    Posts:
    263
    Oh god it's so hard. I don't understand any of the code after reading for 2 hour. There's a lot of new class reference and I got lost in the spiderweb.
    I really appreciated your work author. But could you help me in my specific case? You don't hve to write code for me just guide me in a right way please.
    I want to be able to control the the percentage of "Spline mesh tiling".
    For example, when the percentage is 1, the mesh will fill all the node from first to last.
    When the percentage is 0.5, the mesh will only fill halveway from the distance of firstnode and lastnode.
     
  14. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    Have you seen the growing root example? It seems to be exactly what you are looking for.
     
  15. jiraphatK

    jiraphatK

    Joined:
    Sep 29, 2018
    Posts:
    263
    Thanks you a lot for fast reply.
    I manage to archieve what I need almost perfectly, except that by changing node scale, there will be jagged corners and strecthed uv if I extend it too long. Creating a cylinda that has lot of section can solve this but is not ideal in my situation. I want to simulate a water flowing through long water pipe.

    I managed to do it in two way.
    1. I modified the ContortAlong script like this
    upload_2019-9-17_15-11-41.png
    here's the result
    upload_2019-9-17_15-12-6.png


    The same is true for growing root


    I'm trying to mess with Repeat mode. It seem to not stretch mesh and uv but I'm having a hard time making it animate smoothly.
     

    Attached Files:

  16. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    First, let's talk about the filling mode:
    - Stretch mode will stretch the mesh to fill the interval you set. Stretching the mesh will indeed stretch the UV and the texture as well.
    - Once mode will only place a single mesh without changing it's scale, at the beginning of the interval.
    - Repeat mode will place as many meshes as possible into the interval without changing scale. On your gif, the meshes appear whenever the interval becomes big enough to welcome a new mesh.

    To achieve a water flow without stretching the water, we will need an hybrid system. The component will have to place as many meshes as possible (without stretching) into the interval as in Repeat mode, plus an incomplete mesh on the remaining space.

    SplineMesh doesn't allow to curve just a part of a mesh, but it's totaly doable. It will require some low level code, though.

    Also, if you can "hide" the starting of your flow, you can use the repeat mode in the other direction. Reverse the spline, and grow the interval from the end to the start. This way, the mesh will move corretly along the spline, and the new meshes will appear at the beginning, hidden by some graphic element at the source of the flow. I don't know if it is acceptable for your gameplay, though.

    Don't hesitate to ask more, and have fun bending water ^^

    Ben
     
    jiraphatK likes this.
  17. jiraphatK

    jiraphatK

    Joined:
    Sep 29, 2018
    Posts:
    263
    I did it !! Thanks sooo much. I'm planing to dig deeper in to your code still. But this did the trick nicely.
    I put in invisible material at the start of the flow to hide it. work like a charm :):)
     

    Attached Files:

  18. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    Glad to read it ^^

    If you like SplineMesh and want to support, remember you can:
    - show what you're doing with SplineMesh right here,
    - write a short review on the asset store,
    - buy the paid version.

    Have fun bending things !
     
  19. niklaswetterberg

    niklaswetterberg

    Joined:
    Aug 1, 2019
    Posts:
    2
    Than you for your help! I manage to get the road and terrain to follow the spline now and have made some changes in my blender-file in order to make it look a lot better.

    However, as I want to create a very long road (i.e. equivalent to about 40km) I have been told to make the road into several smaller segments in order to make computing easier. When I use the Spline Mesh Tiling script I get the results as one long segment (which I as previously mentioned want to avoid). I found that to get several small segments I can enable Curve space, but this creates holes in the road and terrain. What can I do in order to avoid this issue?

    Hole.PNG
     
  20. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    tl;dr: choose between "stretch" mode on curve space, or "repeat" mode on spline space.

    Let' me explain some things first. Your spline is made of nodes. A "curve" is the cubic bezier curve between two nodes.

    When you ask the SplineMeshTiling to work on curve space, it means that you want to repeat the process of placing a mesh on each curve individualy.

    On the contrary, if you use the spline space, you ask to place the meshes once for the whole spline, wherever the curves are. In this mode, a mesh can start on a curve and end on another.

    Now the fill mode. Whatever the space you choose (curve or spline), you have to decide how SplineMeshTiling will fill the available space. In "once" mode, only a single mesh will be placed at the start of the available space, and it will not be stretched to fill it. In "stretch" mode on the other hand, a single mesh will be placed but it will be stretched to fill the available space. And in "repeat" mode, SplineMeshTiling will place as many meshes as possible in the available space without stretching them. In both "once" and "repeat" modes, you can have a remaining space at the end of the space.

    You can see examples in the showcase:


    Now you understand that you need to work in curve space, with the stretch mode for your road segment to fill the available space. But you may be annoyed by your segments and textures being stretched, if two nodes are far from one another.

    To avoid that, you can try the spline space with repeat mode but in this situation, you won't be able to connect precisely many splines, as there will be a space at the end of the spline. You will have to test the two approaches and choose the best fit. It is also possible to create your own SplineMeshTiling with a fill mode specific to your need.

    Finaly, if you still have a hole between your segments in repeat and stretch mode, there might be a problem with the mesh. In this situation, it's probably a lost invisible vertex outside of the bounds.
     

    Attached Files:

  21. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    Hi @maxizrin, Just to tell that the last patch fixes this bug.

    Do you have any more issue with SplineMesh?
     
    maxizrin likes this.
  22. DanielRMGH

    DanielRMGH

    Joined:
    Sep 20, 2019
    Posts:
    1
    Hey, very interested in the tool based on what I've seen in the tutorial scene, I'm not someone who knows the first thing about coding, especially in Unity so maybe this isn't for me but I had a question regardless. When using the mesh tiling on a spline, I'm trying to replicate what you had going with the tentacle in the tutorial scene and am trying to add a taper to the generated geometry, but when I edit the scale transforms on the spline elements they revert back to 1. Is there something simple I'm missing or is this all edited through code?

    Cheers
     
  23. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    The ExampleTentacle is made to control the scales itself. If you have added this script, then it's normal that you can't change the scales, as the script reset them each frame (even in editor).

    You can either remove this script and set the scales manually, or let it control the scales. In the latter, you will have to change the start and end scale you want in ExampleTentacle's parameters.

    Hope it helps
     
  24. artofmining

    artofmining

    Joined:
    May 1, 2016
    Posts:
    74
    Getting Errors in 2018.2.3f1

    Assertion failed on expression: '(srcInfo.GetChannelMask() & copyChannels) == copyChannels'

    This happens when I run the showcase demo, nothing actually happens within the demo, the errors are generated when I stop the game. It produces numerous errors of the same report - Assertion failed on expression: '(srcInfo.GetChannelMask() & copyChannels) == copyChannels'

    Is there something I'm missing? The asset looks to have great potential but its a bad start so far if I cannot even run the demo.

    Thanks
    Archie
     
  25. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    tl;dr : Unity 2018.2.3 is not a supported version for SplineMesh but it shouldn't be a problem at all.

    Hey this is an old bug in the ligthing of Unity 2018 that has been fixed a long time ago ^^ This should not cause any problem in the SplineMesh showcase (except for the red messages), and would even not appear when using SplineMesh in your own project.

    SplineMesh is uploaded on Unity asset store using the long term service (LTS) versions of the 5.6, 2017, 2018 generations and, of course, the latest one in the current 2019 generation.

    The 2018 LTS was 2018.4.3 when I've last published SplineMesh, and you are trying to use it with 2018.2.3. This is most likely a Unity backward compatibility problem.

    What you can do :
    - Obviously, update your editor to the latest version, or at least the LTS of your current version. It's a good practice but I know it's not always possible or reasonnable.
    - Ignore the messages, as the bug comes most likely from the demo scene settings, not from the asset or the scripts.
    - Change parameters in the scene lighting may reset things and make the messages disappear.

    If none of this helps tell me, i'll try to download your specific Unity version and debug it.
     
    artofmining likes this.
  26. artofmining

    artofmining

    Joined:
    May 1, 2016
    Posts:
    74
    Thanks mate .. It looked to be "Baked lighting" causing issue .. all samples now running in a fashion. I've just sent you a payment for the asset to help you. One thing I would strongly suggest is one or more VERY BASIC getting started videos maybe a mini series . Like creating your first spline and animating an object etc. I understand I can reverse engineer your demos to learn but sometimes us simple folk need a quick "how to" showcase in video format with audible explanation. They dont have to be too detailed but I'm sure it would also promote your asset better. Its a time issue with indies like me as I wear too many hats (from modelling to code and everything in between) and don't always have time to work through all the examples or read forums too often. Your videos show what can be done but not how to get there. Good work keep it up !
     
  27. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    Thanks for the support and the advice.

    I know it's far from perfection, but have you seen this video? It's the closer to a tutorial that I have made for SplineMesh.



    Please note that I am (or try to be) quite present and reactive here on the forum to support SplineMesh users, so don't hesitate to ask if you need assistance.

    Have fun bending things !
     
  28. artofmining

    artofmining

    Joined:
    May 1, 2016
    Posts:
    74
    No worries and thanks. Yes I'll take a look!
     
  29. vongsawat

    vongsawat

    Joined:
    Mar 26, 2014
    Posts:
    7
    Hi, just started messing around with the asset, but experiencing some weirdness right from the start..
    Spline Inspector always shows No Selected Node, and I can't manually change values in the Node array.
    Halfway through messing around, it suddenly worked for a couple of minutes, then reverted.
    Not sure if either of the following console errors are related, but including them anyways:

    Had hundreds(?) of this error show up in the Console in an existing project running 2018.3.14f1:
    Code (CSharp):
    1. SendMessage cannot be called during Awake, CheckConsistency, or OnValidate
    2. UnityEngine.Transform:set_parent(Transform)
    3. SplineMesh.UOUtility:Create(String, GameObject, Type[]) (at Assets/SplineMesh/Scripts/Utils/UOUtility.cs:10)
    4. SplineMesh.ExampleContortAlong:Init() (at Assets/SplineMesh/Scripts/Example/ExampleContortAlong.cs:66)
    5. SplineMesh.ExampleContortAlong:OnValidate() (at Assets/SplineMesh/Scripts/Example/ExampleContortAlong.cs:45)
    6.  
    Problem persists on a clean project in both 2018.3.14f1 and 2018.4.9f1, also have a warning the console but unsure if related or not seeing as it's for MeshBender: Assets\SplineMesh\Scripts\MeshProcessing\MeshBender.cs(264,36): warning CS0162: Unreachable code detected
     
  30. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    About the "no node selected" bug, I've already heard about it without having the chance of reproducing it. It seemed to be a problem about the Unity installation and disappeard after a cleaning, but I can't confirm.

    I'm interested in some debugging about it, so if you have the patience to try and find what's going on in SplineEditor, please let me know. I would do myself but I have no clue how to reproduce it on my computer.

    About the "send message" error, it's annoying but harmless. The immediate destruction of UnityObject is now forbidden during OnValidate in edit mode, which causes the message. Rules are changing very fast since a year or so on this subject, and I still have to find the perfect solution. It should not bother you, or may even not appear on your own project using SplineMesh.

    Finaly about the dead code warning, there is indeed an experimental feature that needs to be finished here (looping splines) Everything works ok but the code is not clean.

    Thanks for the report.
     
  31. irenya

    irenya

    Joined:
    Nov 22, 2017
    Posts:
    10
    Hi, @methusalah999 ! First of all, thank you so much for such an awesome asset!!
    Have been playing around with it, and so far it all seems to work great, but i do have an issue with colliders. I have a pretty simple setup, the idea is to drag a node around during runtime and add new nodes if necessary, think of carrying a cable around. Visually it looks great with a setup just like the cables in the showcase scene, adding the smoother to improve the transitions between nodes.
    Now, i can see the collider fine before moving the spline, but as soon as i drag the nodes, the collider seems to stay in the original place. This also happens in the showcase scene with the cables. The colliders won't update either in play or edit mode. If I enable the "Convex" option, though, it creates a convex collider at the correct spot and when i disable convex, then the regular collider appears in the correct place. It would seem as if the collider is not updating its position, and toggling the Convex field makes Unity recalculate it correctly (I think).
    So I was wondering if there's anything that can be done so that they update in real time.
    Which brings two more questions:
    1) Should the meshes have a kinematic rigidbody? Unity always insists that if you're going to move a collider, it should have a rigidbody so as not to overload the physics engine (colliders without rigidbodies are considered static).
    2) How would one go about sending onCollision messages? Would attaching a script to the mesh work and, if so, what would the best place to do it be?

    Thank you very much in advance, and apologies if the colliders issue is because of something I overlooked. I only started working with the asset today :)
     
  32. vongsawat

    vongsawat

    Joined:
    Mar 26, 2014
    Posts:
    7
    The bug was on a clean install of Unity 2018.4.9f1 not sure where to go from here. Not sure what you mean by cleaning though?

    Not much of a coder so don't know the first thing about debugging editor code :( About all I could figure out was that selection was always null in OnInspectorGUI.
     
  33. stefannew

    stefannew

    Joined:
    Aug 9, 2017
    Posts:
    1
    Hey methusalah999,

    Love the plugin, spline generation is excellent; I'm running into an issue attempting to generate colliders with the SplineMeshTiling script:

    https://imgur.com/a/JlNiAwm

    The gif is a bit clipped, but it seems that the "generateColliders" option is not applying meshes to the spline Mesh Collider:

    https://imgur.com/a/evCO2yn

    I'm trying to figure out what I'm doing wrong. Sorry for the vagueness, is there a better way for me to provide information to help debug/guide?

    Thanks
     
  34. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    Hi there and sorry for the late answer. You both have the same issue.

    tl;dr: mesh colliders won't update at run time due to performance issues.

    You "can" update a mesh collider at run time, on each frame, but this would cause a major performance loss. The mesh collider itself is quite heavy for the physic engine to manage, even more if the mesh has a lot of vertices, so there are many optimizations running at the creation of this special collision shape. If you update that shape each frame, you will force Unity to run these optimizations each frame, and you will most likely be unhappy with the result.

    Try adding a line in a script to call
    meshCollider.Update()
    , or
    meshCollider.mesh = myMesh
    , whatever is the way to make Unity rebuild a mesh collider and make some tests. It may be the solution in some specific situations.

    It's not about Unity or SplineMesh, it's more of a physic simulation issue in general. In most games, the collision shape is very rarely the same as the visual mesh for performance purpose. It's also possible to update mesh collider each frame with good performances, but it's a whole subject.

    If you want to update the collision shape at runtime, you will have much better results using primitives like capsules, spheres and boxes as colliders sowed along the spline. A correct way to do that is :
    - create a prefab with your mesh
    - create a collision profile using primitives
    - duplicate that profile to enough enough "slices" along the bending axis
    - remove the mesh from the prefab

    Now you can create a simple script to place these objects along the same spline as the mesh, so that the primitives will be bent the same way. Of course it will be an approximation.

    Hope it helps.
     
    irenya likes this.
  35. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    I'm sorry @vongsawat but I can't reproduce your bug on your specific Unity version :/

    Here is a twitter conversation I had with a SplineMesh user that encountered the same issue, with no solution provided. I will ask him if he has been able to solve the issue eversince.

    In the meantime, could you try and install the latest Unity 2019 version and tell me if the issue happens? I'm not telling you to switch to 2019, but this test could help me debbuging.

    Thanks in advance.
     
  36. moondust-games

    moondust-games

    Joined:
    Jul 21, 2013
    Posts:
    24
    Hi Benoît, Firstly SplineMesh is fantastic! Could you please help me with a script? I'm not much of a coder (thanks to PlayMaker!) but I'm having a go at editing your growing roots example script to my needs and have got a lot done but I want to be able to reverse a grown root (tentacle in my case) back to zero scale. Think tentacles that creep out of a hole, pause a little then retract back in.

    Here's your Contort routine code. I'm trying to write a ReverseContort with a for loop that iterates back through the nodes but can't seem to get it to work with various scale calculatiosn (which I haven't included below). It always seems to make the scale changes in the same direction or I get weird results whatever I try.

    Any pointers would be really helpful.

    Code (CSharp):
    1.         private void Contort() {
    2.             nodeDistance = 0;
    3.             int i = 0;
    4.             foreach (var n in spline.nodes) {
    5.                 float nodeDistanceRate = nodeDistance / spline.Length;
    6.                 float nodeScale = startScale * (rate - nodeDistanceRate);
    7.                 n.Scale = new Vector2(nodeScale, nodeScale);
    8.                 if (i < spline.curves.Count) {
    9.                     nodeDistance += spline.curves[i++].Length;
    10.             }
    11.             }
    12.  
    13.             if (generated != null) {
    14.                 meshBender.SetInterval(spline, 0, spline.Length * rate);
    15.                 meshBender.ComputeIfNeeded();
    16.             }
    17.          
    18.         }
    19.  
    20.         private void ReverseContort() {
    21.             nodeDistance = spline.Length;
    22.             for (int i = spline.curves.Count; i>0; i--) {
    23.             var n=spline.nodes[i];
    24.  
    25.           //...
    26.  
    27.          }
    28.  
    29.           if (generated != null) {
    30.                 meshBender.SetInterval(spline, 0, spline.Length * rate);
    31.                 meshBender.ComputeIfNeeded();
    32.             }
    33.          
    34.         }
     
  37. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    Don't mess with this code at all. All you have to do is manipulate the "rate" variable as the scales and tentacle length will depend only on this.

    You just have to grow the rate from 0 to 1, then from 1 to 0 and call the same code all the time.

    Ideally, you can add a public AnimationCurve on your script and use AnimationCurve.Evaluate(animationDuration) as rate, so you can control the speed, acceleration, etc. Then you just have to add Time.DeltaTime to animationDuration each frame.

    More about animation curve : https://docs.unity3d.com/ScriptReference/AnimationCurve.html

    Hope it helps !
     
  38. moondust-games

    moondust-games

    Joined:
    Jul 21, 2013
    Posts:
    24
    Thank you! I knew it would be something so simple. I was messing with the rate within my copy of the subroutine but reversing the rate increment was the trick - I've already got it working. Thanks again. I'm "upgrading" from free to paid ;-)
     
  39. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    Thanks for your support and have fun bending things !
     
  40. pizza512

    pizza512

    Joined:
    Sep 24, 2016
    Posts:
    2
    Love the asset. It's working great. The only thing I'm having problems with is manually editing the points. when I type in, for example, a 0 in the x position it goes right back to the previous value, give or take a few decimal points.
     
  41. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    Hi there it's a bug !

    Can you try and go into Scripts/Editor/SplineEditor.cs and delete the line 261
    serializedObject.ApplyModifiedProperties();
    ?

    Please tell me if it solves the problem (and doesn't create any other ;))
     
  42. pizza512

    pizza512

    Joined:
    Sep 24, 2016
    Posts:
    2
    That fixed it. Don't see any other issues yet. Thanks!
     
    methusalah999 likes this.
  43. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
  44. pojoih

    pojoih

    Joined:
    Mar 30, 2013
    Posts:
    220
    Is there, by chance, a possibility, to implement a function to "shrink" a spline, without deforming it? I've read about this as "knot insertion problem", but cant quite wrap my head around it on how to just move the last node without touching the spline path. Would love to see a "InsertNode(float distance)" in Spline.cs
     
    Last edited: Nov 13, 2019
  45. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    I think you could create an intermediate node without changing the curvature.

    Obviously, the position of the node will be a point on the curve.
    Obviously too, the control point will be on the tangent of the curve at that position.
    The challenge is in finding the distance between the new node and its control point (the "direction"). If I'm correct, this distance should be the interpolation of the two (previous and next) control points distance from there respective node, by time t.
     
  46. pojoih

    pojoih

    Joined:
    Mar 30, 2013
    Posts:
    220
    Code (CSharp):
    1.  
    2. var realCutDistance = 0.645f;
    3. var spline = GetComponent<Spline>();
    4. var curve = spline.GetCurve(realCutDistance);
    5. var newEndNode = spline.GetSample(realCutDistance);
    6. spline.InsertNode(1, new SplineNode(newEndNode.location, newEndNode.location + newEndNode.tangent * Mathf.Lerp(Vector3.Distance(curve.n1.Position, curve.n1.Direction),Vector3.Distance(curve.n2.Position, curve.n2.Direction), realCutDistance)) );
    7.  
    Hmmm, does not seem to work. I think I not only have to Insert a new Point but actually alter the other nodes directions as well.
    upload_2019-11-14_2-28-37.png
     
  47. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    I think you are right. Adding a point to a cubic bezier curve without changing topology is not trivial math, at least not for me ^^

    My I ask what you need this for? There is a chance I can find a workaround.
     
  48. JohnSmillie

    JohnSmillie

    Joined:
    Mar 20, 2019
    Posts:
    2
    I'd like to have the ends of my spline follow 2 gameobjects as they move around, whats the best way to do this? I thought about writing a script to set its position to that of the gameobject its trying to follow, but I dont know how to reference the spline node in a script.
     
  49. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    627
    It's spline.nodes.Last()
     
  50. ridethefader

    ridethefader

    Joined:
    Jun 17, 2019
    Posts:
    44
    @methusalah999
    Trying to use Spline Mesh Tiling to create a railroad track that I created in Maya. In the Showcase scene, when I replace the orange Cylinder mesh with the railroad track mesh FBX I created, the cylinder disappears and theres nothing there but the spline. It's like the railroad track mesh is invisible. I know the scale of my mesh is correct as I work in real world metric scale. I have even tried exporting an FBX of a plain cylinder from Maya and replace the orange cylinder, and it disappears as well and just shows the spline itself with no mesh. Using Unity 2019.2.14f1

    I've even tried converting the FBX files to DAE files, and also tried using OBJ files. Nothing worked.
     
    Last edited: Dec 3, 2019