Search Unity

Bézier Path Creator (free)

Discussion in 'Assets and Asset Store' started by SebastianLague, Feb 3, 2019.

  1. SebastianLague

    SebastianLague

    Joined:
    Aug 31, 2014
    Posts:
    111
    Hello, I've created a tool to quickly and easily creating paths for your game. You can make objects move along these paths, or use them as a guide for spawning objects and generating meshes.

    You can download it for free from the asset store.
    See the user guide for a full run-down of the features, or have a look at the video below for a quick overview.
    I hope this will prove useful to some of you!

     
    sumawinata, johnpccd, Rewaken and 7 others like this.
  2. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    936
    Super excellent tool! Thank you for sharing.

    I am trying to understand how I can modify the tool to be able to see the path in the editor when I don't have the path selected. any clues as to how I could make this happen?
     
    pabler343 likes this.
  3. SebastianLague

    SebastianLague

    Joined:
    Aug 31, 2014
    Posts:
    111
    Hi, if you get the latest version from my github you can enable this as an option in the path settings. https://github.com/SebLague/Path-Creator
     
    Kellyrayj likes this.
  4. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    936
    Hi @SebastianLague! Thanks for your speed reply before.

    I've another question for you. I've created a follow path script very much like your example. I'd like to be able to send Unity Events based on where an object is on the path. For instances, if the end of path instructions is set to stop, I'd like to be able to send an event when the object reaches the end of the path. Thoughts on how I can go about doing this?
     
    chazgw likes this.
  5. VanDraven

    VanDraven

    Joined:
    Oct 31, 2012
    Posts:
    6
    Hi, you've made a great tool! I've even signed up to your Youtube channel!
    It seems the path is locked in place, is there a way to move it with the object the script is attached to?
     
    Last edited: May 17, 2019
  6. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Thank you so much for making this tool, it saved me a tremendous amount of time and frustration. :)

    It's probably far outside the scope of what you had in mind, but do you have any suggestions for how we could go about merging meshes if we wanted to have multiple paths cross over each other or form intersections without z-fighting?
     
  7. rudomanenkoanton

    rudomanenkoanton

    Joined:
    Jun 27, 2019
    Posts:
    1
    It seems like there are some mistakes in documentation. When I want to create path from script I use method GeneratedPath from doc. But if I convert bezier path to Vertex path, like in documentation, I get the error message, that Vertex path constructor get more than one parameter.
     
  8. Balours

    Balours

    Joined:
    Nov 27, 2013
    Posts:
    59
    Hi, is there a way to change the color of a curve in the editor without changing the color for every curve?
    Thanks!
     
  9. ml785

    ml785

    Joined:
    Dec 20, 2018
    Posts:
    119
    This is excellent. I'm just wondering, is there a way to set a point's transform as a GameObject's transform? That way, the path constantly updates to follow a moving GameObject's transform.
     
  10. Linsky

    Linsky

    Joined:
    Mar 27, 2017
    Posts:
    1
    Is there a way to make the object to stop at a certain point and keep going after a key is pressed?
     
    chazgw and kshitizsv like this.
  11. meuklight

    meuklight

    Joined:
    Feb 2, 2016
    Posts:
    12
    Very nice and useful asset! Thank you so much!
    Can I create a Bezier Curve and Vertex Curve once and only update the points position other time?
     
  12. unity_VMhu5_JGYBnyOg

    unity_VMhu5_JGYBnyOg

    Joined:
    Jan 4, 2020
    Posts:
    1
    Hello, thank you very much, it is very nice and useful. I have a question with creating path by script, can I update the path? and how can i do that (with script)
     
  13. Fimiam

    Fimiam

    Joined:
    Oct 24, 2016
    Posts:
    13
    Hello, it's really awesome tool!
    Can anyone share a script to align two bezier paths with each other and smooth angles?
     
  14. hhamedware

    hhamedware

    Joined:
    Feb 8, 2019
    Posts:
    3
    hi,
    thanks for this path SebastianLague,
    but i want to know is there way to deactivate and activate this path when i need it or change the path to another path by script.
    thank you.
     
  15. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    Does anyone know how can I tell if my transform has reached the end of it's movement along an open path?

    I have tried all sorts of ways (that didn't work) but I was sure there is probably a simple conditional or callback that can be used.

    I am using (from the documentation) the following in my Update routine:

    Code (CSharp):
    1. if (pathCreator != null){
    2.             distanceTravelled += speed * Time.deltaTime;
    3.             transform.position = pathCreator.path.GetPointAtDistance(distanceTravelled, endOfPathInstruction);
    4.         }

    This all works perfectly but I would like to know when my transform has reached the end of the path. Anyone have an idea what I should be doing?
     
    chazgw likes this.
  16. Aseemy

    Aseemy

    Joined:
    Aug 22, 2015
    Posts:
    207

    Just check if the distance traveled is greater than the total length of the path.

    Code (CSharp):
    1. void Update()
    2.         {
    3.             if (pathCreator != null)
    4.             {
    5.                 distanceTravelled += speed * Time.deltaTime;
    6.                 transform.position = pathCreator.path.GetPointAtDistance(distanceTravelled, endOfPathInstruction);
    7.                 if(distanceTravelled>=pathCreator.path.length)
    8.                 {
    9.                     //reached end
    10.                 }
    11.             }
    12.         }
     
    Last edited: May 26, 2020
  17. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    Thank you @Aseemy ! That works perfectly. Simple and elegant. :)
     
  18. pabler343

    pabler343

    Joined:
    Apr 23, 2020
    Posts:
    1
    Did you have a answer? Y have the same problem
     
  19. rhyswittingslow

    rhyswittingslow

    Joined:
    Feb 24, 2016
    Posts:
    11
    Anyone know if there's anyway to check what point an object thats following the path is at?

    And to have one point branch off to two points?

    Or set each point to have an action, say freeze the movement on the path.
     
    chazgw likes this.
  20. Mike-Foregger

    Mike-Foregger

    Joined:
    Dec 3, 2015
    Posts:
    2
    Is it possible to see the path in the game view so it looks similar to the editor?
     
  21. Aseemy

    Aseemy

    Joined:
    Aug 22, 2015
    Posts:
    207
    you can use a line renderer for that
    get the points of the path and set them in the line renderer
    adjust the line renderer to match the look and feel you want
     
  22. jpsci

    jpsci

    Joined:
    Aug 14, 2020
    Posts:
    1
    Somebody could make a Rigidbody follow a path? Im trying to accomplish this in a 2d enviroment.
    Cheers.
     
  23. Aseemy

    Aseemy

    Joined:
    Aug 22, 2015
    Posts:
    207
    you can set the rigidbody as kinematic and use MovePosition method of the rigidbody to follow the curve.
     
    jpsci likes this.
  24. SpaceSim

    SpaceSim

    Joined:
    May 15, 2020
    Posts:
    3
    why is my object scaled up when i press play? And it also sits way above the path. If i scale it to 0.1 in INspector and i press play the object goes back to scale 1, starts following the Path but it is clashing with walls.
     
  25. Kerphelio

    Kerphelio

    Joined:
    May 28, 2020
    Posts:
    2
    Fantastic tool, thanks for making it available!
    I'm wondering, is there a way to manipulate the shape of an existing path, aka anchor and control points at run-time via script? I did find SetPoint() in the Bezier path, but I'm not sure if changing it at runtime will actually affect the underlying vertex path so I'm wondering if there is a good way to do this. I have been able to eg. read points in from a text file, but while it works "visually", the objects attached to the path will still be following its old shape.
    Only workaround I've found is to instantiate the path after making changes directly to the prefab. Maybe a problem with how the vertex paths are generated? Do I need to manually trigger that somehow?
    What I'm trying to do right now is to move the second-from last anchor point of a path to the position where the player starts, but this position might change, so I'd like to make it so that it adjusts automatically to the pos of the player object when the game starts. I'm sure I could make some complicated contraption where I re-create the entire path from a script, but that sounds like a bit of overkill to just change one little point ;)
    Thank you!
     
    Last edited: Sep 30, 2020
  26. oleh_baziv

    oleh_baziv

    Joined:
    Jan 3, 2018
    Posts:
    3
    Hi @SebastianLague , I have some problems with road generation, I perform path generation, and the road is not updated, but when I click on a game object, then the road is updated, what's the problem? how do i update the road to not click on the game object?
     
  27. Neetesh3D

    Neetesh3D

    Joined:
    Dec 24, 2014
    Posts:
    9
    For anybody looking to achieve the same thing as @Kerphelio mentioned, here's my workaround ( This is by no means the best way to do this, however after searching & experimenting with the code for about a day I was able to figure this working method )

    pathCreatorScript.bezierPath.SetPoint(0, transform.position, false);
    vertPath = new VertexPath(pathCreator.bezierPath, pathCreatorScript.transform);

    First set the Bezier path point, using the new Bezier path you need to create a new vertex path. This will achieve changing the point & the object following the new path. However the Bezier path line won't be updated in the scene view ( unless selected ) which I wasn't able to achieve.

    I'm using this inside a trigger in my project so I can't say if this will have a performance impact if you're doing it in update or so. However for those looking to make it work in more simple scenarios. Hope this helps :)
     
    Kerphelio likes this.
  28. cool_clem

    cool_clem

    Joined:
    Feb 12, 2017
    Posts:
    1
    Hi @SebastianLague ! Very nice tool, thank you for sharing it.
    I'm prototyping something where I need my path to be updated at runtime (I'm adding and deleting segments). I've got everything set up and working but with one issue : My path needs to be selected when entering into play mode for it to be properly updated at runtime. On the other hand, once started I can select anything else in my scene my path will still update.
    Any tips on what could I do to not have to select my path before each time I want to go into play mode ?
    Thanks !
     
  29. Sidadi657

    Sidadi657

    Joined:
    May 15, 2020
    Posts:
    2
    @cool_clem I want to know how to make the path update in runtime
     
  30. Hodja

    Hodja

    Joined:
    Sep 17, 2020
    Posts:
    1
    Please how can i restart my follower
    object?
     
  31. Jointy87

    Jointy87

    Joined:
    Dec 19, 2019
    Posts:
    21
    Hiya,

    First of all, super thanks for sharing this tool with the world! Great stuff!

    But the tool seems broken for me. Whenever I try to create a path, it's not visible in the editor. Only if I DON'T have it selected, does it become visible, but still without handles and points, just the line.

    If I go to the example scenes that come with the package, the same issue persists with the paths in there.

    If I create a completely new unity project with the same version as the project I actually want to use the paths in, the path DOES work fine. So weird.

    I'm using Unity 2020.1.9f1.

    I'm super keen on using your tool for my project, it's so perfect for it. I'm really hoping I can get it to work. Do you have any idea what the problem could be?

    Thanks in advance
     
    Last edited: Dec 22, 2020
    cotevelino, Oldin72, g3trans and 2 others like this.
  32. Roboserg

    Roboserg

    Joined:
    Jun 3, 2018
    Posts:
    83
    How do I iterate over the handles / nodes of a Bezier curve? The nodes we are moving with the mouse
     
    chazgw likes this.
  33. Crawdad

    Crawdad

    Joined:
    Nov 23, 2016
    Posts:
    174
    Hi, Sebastian. Just wanted to say this is a really amazing tool. I've been following your Youtube page for a while, and am always impressed with your work. You have a real knack for making really difficult concepts accessible for dabblers like myself.

    I would like to point out one thing that I feel would help extend this tools versatility. It would be nice to have some way to easily update the anchor points positions during runtime. Maybe make the anchor points child objects, so the transforms are easier to access for dummies like me. I originally downloaded this hoping it would be a good solution to easily launch objects from one point to another on a given path, but without the ability to manipulate the anchors during runtime, it isn't really suited for that. I appreciate that is not really what this tool was designed for, but it would be a nice perk.

    Anyways, thanks again for all that you do. Keep up the good work.
     
  34. thedejavu

    thedejavu

    Joined:
    Feb 4, 2021
    Posts:
    3
    Hello Guys. The object on Path doesnt effect from any collision.How I can solve this problem ? I mean I can not use OnCollisionEnter method for this.Help please.Thx.
     
  35. gaelleBe

    gaelleBe

    Joined:
    Nov 6, 2020
    Posts:
    8
    I have been using Path creator on a project, unity 2020.1,HDRP 2.8.0, and it worked fine. Now I am building another with identical settings, and the path doesnt show. I rtied an imported the 3d object with the path component, and it works, without showing on the scene. Is there something to fix it?

    **EDIT*** The guismo were hidden, so was the path!
     
    resw likes this.
  36. malcolmregan

    malcolmregan

    Joined:
    Feb 12, 2021
    Posts:
    1
    Having this issue as well. I have a script which updates control points every frame, but it only updates in play mode if the gameobject holding the pathcreator script is selected. If anyone knows the solution to this problem please share.
     
  37. icecold043

    icecold043

    Joined:
    Jan 9, 2019
    Posts:
    8
    Still no way to make a point follow a game object? By making it a child, or using a script?
     
  38. laditanpelumi

    laditanpelumi

    Joined:
    Mar 14, 2021
    Posts:
    1
    Hello guys,
    I downloaded this package from the unity asset store and I am trying to follow the scripting tutorial but I keep getting the following error:
    "The type or namespace 'PathCreation' could not be found (are you missing a using directive or an assembly reference?)"
    From my googling so far, apparently the PathCreation namespace should be in the Assets/Plugins folder before I can access it in the script. How do I go about fixing this? Thanks for your help
    PathCreator.PNG
     
  39. the_cerberus

    the_cerberus

    Joined:
    Aug 20, 2019
    Posts:
    10
    Hello,
    i use Path Creator for a RailShooter. It realy works fine, but i have an issue with the Normals. When i use the PathCreator for a 3d Path, the camera is orientated by the normal. In some situations this is not good. How can i disable the normals?
    Thanks
     
  40. wallyRN

    wallyRN

    Joined:
    Nov 2, 2020
    Posts:
    1
    Hi, did you find the fix to this problem? Im stuck on this as well
     
    Last edited: Mar 28, 2021
  41. romi-fauzi

    romi-fauzi

    Joined:
    Aug 16, 2013
    Posts:
    161
    For anyone having issues with updating the spline on runtime without being selected first, here is a solution:

    Code (CSharp):
    1.     private void OnEnable()
    2.     {
    3.         path.bezierPath.OnModified += UpdatePath;
    4.  
    5.     }
    6.  
    7.     private void OnDisable()
    8.     {
    9.         path.bezierPath.OnModified -= UpdatePath;
    10.  
    11.     }
    12.  
    13.     private void UpdatePath()
    14.     {
    15.         path.bezierPath = path.bezierPath; //force bezier path to update
    16.        
    17.         path.GetComponent<PathCreation.Examples.RoadMeshCreator>().TriggerUpdate(); //force road mesh to update
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.         path.bezierPath.MovePoint(id, endPoint); //move the n point to a vector3 called endPoint in inspector
    24.     }
    And upon updating the path, you can also trigger update for the road mesh component, this will also update the mesh.

    Hopefully this helps!
     
  42. mishakozlov74

    mishakozlov74

    Joined:
    Aug 8, 2018
    Posts:
    143
    I think it assumes that you are using assembly definition and link pathCreator to your assembly. Then it works.
    And it's highly recommended to use assembly definitions.
     
  43. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    Hi all, I am attempting to use Path Creator in 2D.

    My path follow script (from the examples) works fine except when my sprite follows the path, it's rotation is changed so it becomes invisible. My path is using 2D (xy) space. I have tried things like flipping normals on the path and using 3D space for the path but these don't work as I would like.

    Any ideas how I can have a sprite follow a 2D path and rotate as it should over the course of the path? Ideally, I would like to be able to see the path and the sprite as normal in my work area and not have to adjust my view to accommodate.

    Thank you kindly!

    -- edit --

    If I comment out:

    Code (CSharp):
    1. transform.rotation = pathCreator.path.GetRotationAtDistance(distanceTravelled, endOfPathInstruction);
    in my Update function, the sprite appears normally and follows the path however it obviously doesn't rotate as it moves.

    Is there an override or offset to this GetRotationAtDistance function?

    Perhaps a more succinct way of putting all of this: is there any way to make my sprite have it's Z axis as up as it follows the path?

    It seems to me that I should be able to adjust the global normals but when I change that axis, my sprite still disappears.


    -- SOLVED - leaving the above for posterity --

    I had to change this function:

    Code (CSharp):
    1. public Quaternion GetRotation (float t, EndOfPathInstruction endOfPathInstruction = EndOfPathInstruction.Loop) {
    2.             var data = CalculatePercentOnPathData (t, endOfPathInstruction);
    3.             Vector3 direction = Vector3.Lerp (localTangents[data.previousIndex], localTangents[data.nextIndex], data.percentBetweenIndices);
    4.             Vector3 normal = Vector3.Lerp (localNormals[data.previousIndex], localNormals[data.nextIndex], data.percentBetweenIndices);
    5. return Quaternion.LookRotation (MathUtility.TransformDirection (direction, transform, space), MathUtility.TransformDirection (normal, transform, space));
    6.         }
    this line:

    Code (CSharp):
    1. return Quaternion.LookRotation (MathUtility.TransformDirection (direction, transform, space), MathUtility.TransformDirection (normal, transform, space));
    has to be changed to this:

    Code (CSharp):
    1. //this needs to be modified to have the first parameter as per A 2D object is always flat on the XY plane, so the Z axis always points forward perfectly,
    2. //so we know that we want the Z axis to end up as (0,0,1), or Vector3.forward for shorthand.
    3. return Quaternion.LookRotation (Vector3.forward, MathUtility.TransformDirection (normal, transform, space));

    And voila, 2D sprites now follow the 3D path and rotate properly as they move along it.
     
    Last edited: Jun 11, 2021
    CC_YN, lvcinfluenza and IndieJustiX like this.
  44. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    Does anyone know if you can animate a mesh 'growing' along a path at runtime? If so, are there any best practices to approach that?
     
  45. Joephillips151

    Joephillips151

    Joined:
    Feb 11, 2020
    Posts:
    1
    Hello everyone who might be watching this,

    I'm trying to figure out how to set different speeds based on which Anchor the object is moving towards. For example, if my path has 4 anchor points, I'm trying to get it to go at Speed 100 from Anchor 1-2. then Speed 200 from Anchor 2-3, etc. etc.

    I cannot for the life of me figure out how to tell which anchor it's currently moving towards. I found pathCreator.bezierPath.NumAnchorPoints and that shows the total number of anchor points.

    Does anyone know how I can get to what I am trying to achieve?

    Thank you,
    Joesph
     
  46. lvcinfluenza

    lvcinfluenza

    Joined:
    Jul 6, 2020
    Posts:
    3
    The modification you did @starfoxy works like charm! I wasn´t able to solve it. THANKS!
     
  47. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
  48. elMartino

    elMartino

    Joined:
    Apr 9, 2013
    Posts:
    4
    Hi All,

    I'm having a problem when building my project. It seems that all kinds of references are missing, while in the editor it runs like a charm. Any ideas?

    I assume there is some conflict with the `UnityEditor` namespace and the package, but I have no idea how to fix this.

    the console output looks like this.
    Code (CSharp):
    1. Assets\PathCreator\Core\Editor\PathEditor.cs(70,30): error CS0115: 'PathEditor.OnInspectorGUI()': no suitable method found to override
    2. Assets\PathCreator\Core\Editor\PathEditor.cs(5,19): error CS0234: The type or namespace name 'IMGUI' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
    3. Assets\PathCreator\Core\Editor\Helper\PathHandle.cs(42,119): error CS0246: The type or namespace name 'Handles' could not be found (are you missing a using directive or an assembly reference?)
    4. Assets\PathCreator\Core\Editor\PathEditor.cs(12,31): error CS0246: The type or namespace name 'Editor' could not be found (are you missing a using directive or an assembly reference?)
    5.  
    6.  
    Using Unity 2020.3.8f1
     
  49. elMartino

    elMartino

    Joined:
    Apr 9, 2013
    Posts:
    4
    2021092021 update: I fixed it by re-importing the package.
     
  50. Roboserg

    Roboserg

    Joined:
    Jun 3, 2018
    Posts:
    83
    bump