Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    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:
    290
    Thanks for your report.

    Exception on adding a node after the last node has been corrected and will be pushed in the next version. For the undo bug, I don't have a clue, this undo framework is a mystery for me and it will take some more efforts.

    The good news is that both these bugs only affect the inspector drawing. Please enable/disable the gameobject to make them disappear.
     
  2. NewSystemGames

    NewSystemGames

    Joined:
    May 23, 2017
    Posts:
    296
    Is Something like this possible to make?
     
  3. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    Nope, SplineMesh doesn't support spline branching natively. Of course, you can extend it by yourself.
     
    Last edited: Jun 29, 2019
  4. tgd-uni

    tgd-uni

    Joined:
    Dec 16, 2018
    Posts:
    9
    I have been working on something similar last month. This is an altered version of the spline extrusion example from the package. It extrudes a mesh along two splines and branches at a point where the tracks have their full width in respect to the start width. It is not perfect and still wip but i want to make a point that you can do a lot with the splinemesh "system" and i would have been nowhere near this result if not having splinemesh as a solid foundation to begin with. Thanks again for sharing this and all the useful examples it ships with.

    upload_2019-6-29_13-33-30.png
     
    methusalah999 likes this.
  5. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    @sma
    Thanks a lot for these kind words ^^ @Smart-hawk1 have you seen this? Maybe you guys could share some code.

    And if you like SplineMesh, don't forget to write a review on the asset store, it's gold to me.

    Have fun bending things !
     
  6. Gengseng

    Gengseng

    Joined:
    Feb 25, 2017
    Posts:
    5
    It doesn't work in a mobile (android) environment. Is there something that you think is the reason?
     
  7. Gengseng

    Gengseng

    Joined:
    Feb 25, 2017
    Posts:
    5
    i find it.... [ExecuteInEditMode]

    This was the problem, and it's working normally on the mobile. Some update runs need to be changed to InGames.
     
  8. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    SplineMesh is not tested on mobile platform. Still, I don't know why ExecuteInEditMode is causing issues for mobile. Could you elaborate?
     
  9. NewSystemGames

    NewSystemGames

    Joined:
    May 23, 2017
    Posts:
    296
    methusalah999 likes this.
  10. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
  11. NewSystemGames

    NewSystemGames

    Joined:
    May 23, 2017
    Posts:
    296
    Not Really XD, This is more of a side project i wanted to make and nothing serious however i just upload some gameplay on youtube:
     
  12. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    The game is simple yet very fun and quite beautiful. Nice job ! Thanks for the video, I'll link it on my twitter account.
     
  13. Gengseng

    Gengseng

    Joined:
    Feb 25, 2017
    Posts:
    5
    Some of the updates were wanted to be processed by Android builds in real time. However, the problem was that the declaration forced the update into "some situations." You wanted them to work in the thin view. After I saw your assets, I was overwhelmed with great inspiration and started producing small game ideas with them. Finally, I changed the instruction to [ExecuteAlways], and then deleted it completely. This required some code to be moved into the normal 'update' function.
     
  14. Gengseng

    Gengseng

    Joined:
    Feb 25, 2017
    Posts:
    5
    And...I have Question. sir. What exactly does the 'Up' function on the spline? This value causes the mesh to twist completely, making normal testing impossible. I've adjusted the numbers, and I've become somewhat stable, but there's an intermittent mesh-twisting error. (A frame, the mesh twists and turns back to normal.) I'm frustrated that the conductor doesn't know why.) Because I put a collider on my mash, this one-frame error is fatal to gameplay. The splines I've created are not complex forms. This spline doesn't move on the z-axis, but turns around one turn in an oval and returns to its place. I've read the 'Description' on the code, but I can't understand the description properly. I need your help
     
  15. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    Up vector allows you to specify the upper direction of your bent content at each node. It is used in place of the roll to resolve mainly two problems:

    First problem, if the spline goes vertical, a gimball lock occur. That means the yaw and pitch axes are overlapping and the spline doesn't know where the up is. In any other siutation, the up is in the sky, but when you head to the sky, the up need to be defined manually, or else it will be choosen for you and twist will certainly occur.

    Second problem is the looping. If nothing is specified, the up is in the sky. When you create a loopingfor example, you want your road to head down, not up. Specifying the Up downward make the spline understand that you want the content to be upside down.

    Please, don't try to use both custom roll and custom up for the same spline. The two systems are not working well together.
     
  16. ssharkk

    ssharkk

    Joined:
    Oct 14, 2017
    Posts:
    3
    I have been playing around with this tool and it works great overall. I have found a few issues though: First, I can't get the SplineExtrusion script to create a working collider, even the showcase scene demo doesn't want to work. I've tried deleting the asset and reinstalling it from the asset store multiple times and I even upgraded my Unity version from 2019.1.1 to 2019.1.10 but there's just no way to get it to collide with other objects. The ball in the showcase falls straight through the spline and also there is a problem with the rope demo, where I can see the physics working via Scene view during play mode, but the visible spline doesn't follow, it is just static. Is there anything I could be doing wrong? Maybe my scene settings have a wrong setting (though I'm using just the default settings on a new project)? I'm guessing the fact that the mesh shows no name (as shown in the screenshot below) might be a clue but I have no idea how to fix that as I'm not confident in the way you generate the mesh. BrokenMeshCollider.png
     
    Last edited: Jul 18, 2019
  17. ssharkk

    ssharkk

    Joined:
    Oct 14, 2017
    Posts:
    3
    I have just found out that if during play mode I apply any Physic material to a selected segment collider, all of a sudden the collision gets generated. After some more fiddling around I found out that the scripts can work under some circumstances. I think there must be something going on with the refreshing of certain parts. I can refresh the collider generation during play mode but it doesn't persist after I stop and play again. All I do is: for rope demo, I have to disable then enable Curve Space parameter during play mode, and for the Extruder demo, I first comment out the [ExecuteInEditMode] line (on line 24 in SplineExtrusion) - this will make it so the collider gets generated when I Exit Play mode (i.e. enter Edit mode), however if I play again, the collider gets destroyed upon start and then generated again when stopped play mode. This way, I can disable the SplineExtrusion script once I do this step and the collision is then there. The problem with this is that this should work out of the box and is unbearable for actual use. Any solution to this?
     
  18. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    I've reproduced the bug with extrusion collider and I will dig into it.

    As for the rope, I can't see any problem. I suspect it is the Unity batching bug occuring on your setup. Please try to uncheck static batching in project settings -> player -> other and tell me if you can then see the rope update correctly in play mode.
     
  19. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    I've just pushed a fix on the github repository here

    On line 203 of ExtrusionSegment, just re-assign the sharedMesh in the MeshCollider each time the mesh is updated.

    Should do the trick. It will be live on the store with next release.
     
  20. ssharkk

    ssharkk

    Joined:
    Oct 14, 2017
    Posts:
    3
    That's awesome, yes the static batching solved the rope demo and the patch for ExtrusionSegment solved the no collision problem. Thanks for such a quick response!
     
  21. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    You can find more info on the batching bug here. It's still not resolved afaik, so avoid cancelling your builds !

    I have no other workaround than disabling static batching, which is far from ideal sadly.
     
    ssharkk likes this.
  22. Kateryna_S

    Kateryna_S

    Joined:
    Jun 27, 2018
    Posts:
    2
    Hi, I have a question. How to add two different meshes on one spline? Like it was done here:
     

    Attached Files:

  23. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    This track has been made with the ExampleTrack script provided in SplineMesh. You won't see it in the showcase, it's only in the code.

    Basicaly, you have to write your own script to create a MeshBender at each node with different meshes (from a mesh list for example).
     
  24. Kateryna_S

    Kateryna_S

    Joined:
    Jun 27, 2018
    Posts:
    2
    Thanks)
     
  25. bigbenmatt

    bigbenmatt

    Joined:
    May 30, 2019
    Posts:
    11
    Hiya

    Great tool. I've been using it in 2018.3.8f1! I've just updated to 2019.1.12f1 and as they've stopped input when the alt key is down i can't create new nodes :?. Is this anything that being planned on being resolved

    Ben
     
  26. hsjaaa

    hsjaaa

    Joined:
    Apr 30, 2016
    Posts:
    29
    In the example it says no procedual spine generation, what does that mean? Is it possible generate mesh arrow moving in curve from one object to another which is also moving?
     
  27. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    Hi there !

    In SplineMesh version 1.3, a button now allows you to create a new node after the selected one, from the inspector.

    It's here.
     
  28. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    What you are talking about seems totally doable with SplineMesh.

    The "no procedural generation" things means that SplineMesh does not draw the spline itself, like placing a flexible pipe that has fallen on the floor, project a road network on a terrain or bend a cable between two pillars.

    That said, if you need to create or edit the curve procedurally, you can check the showcase and the RopeBuilder script, which draw and update a spline at runtime, to bend a physic hung rope.
     
  29. maxizrin

    maxizrin

    Joined:
    Apr 13, 2015
    Posts:
    15
    Hi everyone, I was asked to post this after writing a review for the asset, so here it is.

    I was having trouble with one of the scripts significantly slowing my game down.
    According to the profiler "ExtrusionSegment.cs" 's Update method was the cause.

    I patched it out like this:

    Code (CSharp):
    1. private void Update() {
    2.             if (disableNow) {
    3.                 enabled = false;
    4.             }
    5.             if (disableAfterStart) {
    6.                 disableNow = true;
    7.             }          
    8.             ComputeIfNeeded();
    9.         }
    Allowing it to run for one frame before disabling it.
    This seemed to have fixed the issue, and everything works as expected.

    All I'm doing is using the provided "Spline" & "SplineExtrusion" components to create hanging wires.
    10 nodes, "Wet Black" material.
    The extrusion shape is a triangle with an edge length of 0.02
    Every other node has a very small direction vector (Magnitude of ~0.5), to make the wires look like they're hanging off a hook.
    The entire object hierarchy is marked as static.

    That's all the info I thought could be of any use.
     
  30. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    I suppose it is related to this issue : https://github.com/benoit-dumas/SplineMesh/issues/26

    It's fixed with a single line of code on the public repository here. Asset to be updated on the store soon.

    Thanks to you for pointing this bug !
     
    Last edited: Aug 14, 2019
  31. NewSystemGames

    NewSystemGames

    Joined:
    May 23, 2017
    Posts:
    296
    I've been having problems with the direction arrows being locked (Unable to move any of the directions)... Unsure if you're aware of it or not and unsure what causes it yet although I'm pretty sure it has to do with SplineSmoother.cs

    Possible way to reproduce it is to create several connected nodes and then add spline smoother component
     
  32. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    The role of the smoother is to choose directions automatically. So yes, directions are not movable when the smoother is on.
     
  33. NewSystemGames

    NewSystemGames

    Joined:
    May 23, 2017
    Posts:
    296
    Ah I see, I've just updated my splinemesh asset and was just experimenting with new components.... What if you wanted to create a loop, Wouldn't you need to manipulate directions to achieve circular shape?
     
  34. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    Yes you will have to remove the smoother and tweak directions to your specific need.
     
  35. NewSystemGames

    NewSystemGames

    Joined:
    May 23, 2017
    Posts:
    296
    Is it possible to change vertices for individual nodes?
     
  36. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    I don't understand. Bending only a part of a mesh?
     
  37. NewSystemGames

    NewSystemGames

    Joined:
    May 23, 2017
    Posts:
    296
    For spline extrusion component, Only the first node's vertices are editable:

     
  38. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    It's not the first node, it's the profile to extrude. You can't change the profile along the spline.
     
  39. Pekay12

    Pekay12

    Joined:
    Aug 19, 2019
    Posts:
    6
    Hey there!
    First of all thanks for creating this great plugin for free!

    I'm trying to use my own mesh for the Spline Mesh Tiling script to create some cables. After trying out different ways of import my mesh, I figured out that even after just duplicating the Cylinder you included in the DemoAssets folder and trying to use that, it won't work. So I assume the problem lies not in my import settings. The mesh just doesn't show. Any idea there?
     
  40. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    Please check the scale. The object might be there, but very small.
     
  41. Pekay12

    Pekay12

    Joined:
    Aug 19, 2019
    Posts:
    6
    That doesn't seem to be it.

    When I have a segment selected it also shows me a warning in the inspector und Lightmaps "Mesh used by the renderer doesn't have normals. Normals are needed for Lightmapping" which is weird because I use the same mesh somewhere else without that error. Thought it might be a clue.
     
  42. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    I can't tell what wrong with your mesh without having a look at it. Could you please send it to me via private message?

    You said there is the same issue when you "duplicate" the asset's original cylinder mesh. Could you explain exactly what is your pipeline?

    SplineMesh have been tested with a lot of different meshes from different sources. It's certainly nothing important.
     
  43. NewSystemGames

    NewSystemGames

    Joined:
    May 23, 2017
    Posts:
    296
    Is it possible to create prefabs of generated meshes? it doesn't seem to work for me?
     
  44. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    tl; dr : don't save the generated content inside your prefab.

    SplineMesh is procedural generation. Ultimatly, you CAN save the generated result as a prefab but I would advise against it. If you include the generated content in the prefab, you will face the following issue :

    Procedural generators (like SplineMeshTiling, ExampleSower or SplineExtrusion...) needs to delete the previous content and build it again in a lot of situation, like you changing a parameter. Since Unity 2018, you can't delete a gameobject in an instance of a prefab, which is good. If the generated content is saved into the prefab, the procedural generator will try to delete that to build it again and face the instancaited prefab restriction, with an exception.

    The "correct" way is to save only the procedural generator in your prefab, and delete the generated content before saving you asset (and each time you save your asset). This way, the generated content will be created in the scene when the game is launched only (and in the editor if your scripts use ExecuteAlways, as most of SplineMesh buit in scripts work).

    I wish I could flag or attribute or anything on a GameObject, so it is automaticaly NOT saved when you edit your prefab, but it seems to me that such feature is still missing in the lateste Unity. So you have to delete your generated content manually before saving.

    Please note that you should also delete the generated content before saving you scene, to keep it lightweight. the fact tha all generated content is named "generated by..." makes it easy to find game objects by searching the keyword, then delete all.

    Hope it helps.
     
  45. Pekay12

    Pekay12

    Joined:
    Aug 19, 2019
    Posts:
    6
    Thanks for taking the time to help me here! I sent you one of the meshes I tried it with.

    About the duplicate thing: I copy pasted the cylinder.dae file which was included in the DemoAsset folder, created a new spline, added the spline mesh tiling script and assigned the the cylinder mesh to the mesh slot.

    It works fine with the mesh from the original cylinder.dae file but with the copy it doesn't. I get the same result with all my other meshes I tried it with.
     
  46. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    Everything is looking just fine on my side : I can duplicate the included cylinder and use it without issue, and I can use the mesh you have sent me, which has no base, fewer vertices, and correct normal smoothing, without any issue at all (Unity doesn't tell me about any normal issue neither).

    I've tried your mesh on all the SplineMesh showcase and seen no problem.

    Can you try to replace a mesh in the showcase scene by yours, to validate that we have the same result on your side (just drag your mesh in place of the "cylinder")? Then can you explain more about the way you are creating your own spline? Sorry but I can't see where the problem is coming from.

    upload_2019-8-22_22-3-22.png
     
  47. goowin

    goowin

    Joined:
    Sep 9, 2018
    Posts:
    3
    Awesome asset .. thanks a lot ( I give it 5 stars at asset store ) it really deserve more.

    Hi methusalah999,
    I'm new at unity and game development in general.

    I want to move a GameObject along the curve at a constant speed and at the same time I want to know on which curve (spline.curves[index]) the GameObject exists at every moment

    -- When I use ExampleFollowSpline script --
    ==================================
    I can determine where the object is on the spline .. curve 1, curve 2,... but the speed varies depending on the length of the curve.
    + there ( something that confuses me ) is a kind of slowdown at the end and beginning of each curve.

    -- When I use ExampleContortAlong script --
    ==================================
    The speed is constant but I can't determine on which curve the object exists now
    In addition, I don't have a (sample.location) to manipulate the object on one of the axis ( like jumping for example on Y axis )
     
  48. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    290
    FollowSpline has indeed a variable speed, as the follower works on spline time. In cubic bezier curves, the time is a value from 0 to 1 representing the control points travelling at constant speed.

    Therefore, the distance on the curve is not constant and vary according to the curvature. It will indeed tend to slow at each node, as nodes are flatter on the example.

    FollowSpline is made this way for the sake of code simplicity.

    ContortAlong doesn't use the curve time, but the distance in world unit. So the speed is constant, and the spline sample is found using GetSampleAtDistance(float dist).

    Question : why do you need to know on which curve you are?

    I propose you this script. I haven't tested it, but it should do the trick.
    Code (CSharp):
    1. public class FollowSplineWithConstantSpeed : MonoBehaviour {
    2.     private GameObject generated;
    3.     private Spline spline;
    4.     private float traveledDistance = 0;
    5.  
    6.     public GameObject Follower;
    7.     // a speed in world unit (meter?) per second
    8.     public float SpeedMPS;
    9.  
    10.     private void OnEnable() {
    11.         traveledDistance = 0;
    12.         string generatedName = "generated by " + GetType().Name;
    13.         var generatedTranform = transform.Find(generatedName);
    14.         generated = generatedTranform != null ? generatedTranform.gameObject : Instantiate(Follower, gameObject.transform);
    15.         generated.name = generatedName;
    16.  
    17.         spline = GetComponent<Spline>();
    18.     }
    19.  
    20.     private void Update() {
    21.         var traveledDistanceThisFrame = SpeedMPS * Time.deltaTime;
    22.         traveledDistance += traveledDistanceThisFrame;
    23.         if (traveledDistance > spline.Length) {
    24.             traveledDistance -= spline.Length;
    25.         }
    26.         PlaceFollower();
    27.     }
    28.  
    29.     private void PlaceFollower() {
    30.         if (generated != null) {
    31.             CurveSample sample = spline.GetSampleAtDistance(traveledDistance);
    32.             generated.transform.localPosition = sample.location;
    33.             generated.transform.localRotation = sample.Rotation;
    34.  
    35.             // if your really need to know the curve you're on
    36.             // (but SplineMesh tried is best to avoid that you need it, as CurveSample contains all you need)
    37.             float distance = traveledDistance;
    38.             CubicBezierCurve curve;
    39.             foreach (CubicBezierCurve c in spline.curves) {
    40.                 // test if distance is approximatly equals to curve length, because spline
    41.                 // length may be greater than cumulated curve length due to float precision
    42.                 if (distance > c.Length && distance < c.Length + 0.0001f) {
    43.                     distance = c.Length;
    44.                 }
    45.                 if (distance > c.Length) {
    46.                     distance -= c.Length;
    47.                 } else {
    48.                     curve = c;
    49.                     break;
    50.                 }
    51.             }
    52.  
    53.         }
    54.     }
    55. }
    56.  
     
  49. Pekay12

    Pekay12

    Joined:
    Aug 19, 2019
    Posts:
    6
    Alrigth I figured it out, that read/write setting was off... upload_2019-8-22_23-55-35.png

    Thanks for your help anyway!
     
    methusalah999 likes this.
  50. goowin

    goowin

    Joined:
    Sep 9, 2018
    Posts:
    3
    Thank you so much for your quick reply.

    The gameObject follow the spline at a constant speed exactly like what i wanted.

    About the second issue :
    I just need to know the NUMBER of the curve i'm on .. ( or the node number ) not the whole things inside the
    foreach (CubicBezierCurve c in spline.curves) .. I don't know how to find it !!

    Untitledw2.png

    I appreciate so much your efforts .. Thank you again for your help
     
unityunity