Search Unity

[RELEASED] Curvy 2 - the ultimate spline solution

Discussion in 'Assets and Asset Store' started by Jake-L, Sep 29, 2015.

  1. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Check out the shape scripts (CSCircle.cs, CSPie.cs) on how to do arcs. If that doesn't help, perhaps start a thread in our support forum and provide some images. After all it's all about clever handle placement.
     
    amasinton likes this.
  2. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    197
    Hey Jake,

    Do you know if Curvy Spline is compatible with PS4? I just started our port to PlayStation and I am getting some ExecutionEngineException: Attempting to JIT compile method errors.

    Thanks,
    Colton
     
  3. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    197
    FYI switching the scripting backend from Mono 2x to IL2CPP seemed to make curvy work on the PlayStation.

    Cheers,
    Colton
     
  4. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    That's good to know, thanks!
     
  5. SpaceRay

    SpaceRay

    Joined:
    Feb 26, 2014
    Posts:
    455
    Hello, I want to ask how was done the effect of the neon cables or pipes of the trailer scene of the first video shown on the first post of the first page. What was used?

    Thanks
     
    Last edited: Nov 9, 2016
  6. James-Williams

    James-Williams

    Joined:
    Aug 30, 2016
    Posts:
    26
    is there a way to rotate the control point?
     
  7. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Just select the control point and use the standard Unity rotation tool.
     
  8. James-Williams

    James-Williams

    Joined:
    Aug 30, 2016
    Posts:
    26
    Ok thanks. One last question. I do not want the object with the SplineController script to move to the first CP by default. I have written a script that keeps the first point at the exact location of the spline controller object and on button press start leave the first CP where you are and start moving along the spline. problem is that when i start moving along the path if i am not facing the direction of the path upon button press then my rotation is snapped to math the correct orientation. is there a way to ease this? Also do i have to start at the first point?
     
  9. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    Hi there!

    After updating from version 2.0.2 to 2.1.1, I'm not able to edit the initial position of the Spline Controller at runtime anymore. The variable just won't change from 0.
    Am I missing something?

    Thanks
     
  10. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    How do you change InitialPosition? You can't change it in the inspector at runtime, but this little test I just wrote works (attach to a GameObject having a SplineController:

    Code (csharp):
    1.  
    2. using FluffyUnderware.Curvy.Controllers;
    3. using UnityEngine;
    4.  
    5. public class test : MonoBehaviour {
    6.     public bool go;
    7.  
    8.     void Update () {
    9.         if (go)
    10.         {
    11.             var con = GetComponent<SplineController>();
    12.             con.Stop(); // just in case it's running
    13.             con.InitialPosition = Random.Range(0, con.Spline.Length);
    14.             go = false;
    15.         }  
    16.     }
    17.  
    18.  
     
  11. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Not sure if I understand you right. Are you moving the spline's CP to match the controller's position? Perhaps you could show a picture to clarify...
     
  12. James-Williams

    James-Williams

    Joined:
    Aug 30, 2016
    Posts:
    26
    yes OntriggerEnter I am moving the splines first control point to match that of the controller SetParent(1st control point); until I exit the trigger. Upon exit I unparent the 1st control point and then call the splineControllers play method to begin moving the controller along the path leaving the 1st control point behind where i exited the trigger. problem is that once it calls the method if the car is not oriented or facing the direction of the path flows then the car snaps to the correct orientation before it moves. I am loooking for a way to make the process seamless.
     
  13. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    Thanks for your reply,

    I see the problem now. Your example works in Update, but not in the Start method. Somehow the value of initialPosition arrives before the Spline Controller is fully operational I guess? In the earlier version this was not an issue. How could I solve this? It's quite important because I am instantiating Gameobjects with a Spline controller component in front of the player position.

    Best regards
     
  14. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    We have a section about it in the docs, please see here!
     
  15. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I've used Curvy a lot, but only for path following. I'm not very knowledgeable in Curvy's more advanced features like generation. I'm wondering if Curvy is able to do something for me. I have a set of race track prefabs to build roads for a racing game. Is it possible to attach a series of road segments to a curvy spline and have curvy conform the segments to the spline shape so that I can have the road follow the terrain? If so, where would I start with learning how to do that?
     
  16. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    Thanks a lot!
     
  17. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    Hello, I'm sorry to bother you again, but I'm still running into some issues about setting the initialPosition at Start.

    The problem happens when I am catching the Spline from a GameObject in the scene, and then assigning it to a curvy controller at runtime.
    I make sure the spline is initialized with a coroutine, I even checked if it was initialized when assigned to the curvy controller. However the initial position doesn't update when getting a new value.

    After a bit of research I also found the SplineController property "isInitialized". I made a coroutine for that too, but no matter the time it waits it never gets true.

    It would be awesome if you could write me a simple example of catching the spline, assigning to a controller and changing the initial position. Below is the test code I have so far.

    Thanks!

    Code (CSharp):
    1. public class Test : MonoBehaviour
    2. {
    3.     void Start()
    4.     {
    5.         SplineController con = GetComponent<SplineController>();
    6.         CurvySpline mainSpline = GameObject.FindGameObjectWithTag("Spline").GetComponent<CurvySpline>();
    7.  
    8.         Debug.Log("main spline initialized: " + mainSpline.IsInitialized); //Reads false
    9.  
    10.         StartCoroutine(Start(con, mainSpline));
    11.     }
    12.  
    13.     IEnumerator Start(SplineController controller, CurvySpline spline)
    14.     {
    15.         if (spline)
    16.         {
    17.             while (!spline.IsInitialized)
    18.             {
    19.                 yield return null;
    20.             }
    21.         }
    22.  
    23.         Debug.Log("main spline initialized after waiting loop: " + spline.IsInitialized); //Reads true
    24.  
    25.         if (controller)
    26.         {
    27.             controller.Spline = spline;
    28.  
    29.             Debug.Log("controllerSpline initialized: " + controller.Spline.IsInitialized); //Reads true
    30.             Debug.Log("controller dependencies initialized: " + controller.DependenciesInitialized); //Reads true
    31.             Debug.Log("controller initialized: " + controller.IsInitialized); //Reads false
    32.  
    33.             while (!controller.IsInitialized) //This loop has no end, as controller never gets initialized
    34.             {
    35.                 yield return null;
    36.             }
    37.  
    38.             Debug.Log("controller initialized after waiting loop: " + controller.IsInitialized);
    39.  
    40.             controller.InitialPosition = Random.Range(0, controller.Spline.Length);
    41.            
    42.             Debug.Log(controller.InitialPosition);
    43.         }
    44.     }
    45. }
     
  18. socoman3

    socoman3

    Joined:
    Jan 31, 2014
    Posts:
    19
    Nevermind, I found what was missing.
    After assigning the spline, the method "Prepare()" has to be called in order to initialize the controller.

    Best,
     
  19. LoftyTheMetroid

    LoftyTheMetroid

    Joined:
    Oct 26, 2012
    Posts:
    57
    I posted this on the Fluffy Underware Support Forum, but I didn't receive a response. I'll copy/paste here, see if I have better luck:

    One of our uses for CurvyGenerator is to automatically build and place repetitive geometry in environment assets. For example, we'll use it to generate columns around the perimeter of a Roman temple. We would then like to turn the entire GameObject into a prefab and use those prefabs across several scene environments.

    However, we're having an issue when it comes to turning these assets into prefabs. An asset with CurvyGenerator can be turned into a prefab just fine, but if we instantiate it, it will immediately lose its prefab connection. I believe this is due to CurvyGenerator.Update() in the editor, which is called due to ExecuteInEditMode. It will immediately call Initialize(), which in turn will call Refresh(true). This causes a CreateGameObject module in the generator to refresh, deleting its current managed resources while creating new ones. This last bit is what breaks the prefab connection.

    This isn't ideal for us, so I was wondering what the recommended workflow is for our use case? Currently, the only ways I see around this are to either disable the CreateGameObject module after generating its resources at edit time, or to not include the CurvyGenerator in the prefab and instead generate the geometry separately, after which we pull the geometry into the prefab and update it. Both of these solutions aren't super satisfactory, since it adds extra steps (and potential opportunities for forgetfulness or mistakes) to our prefab process. Do you recommend a different approach?

    Thanks!
     
  20. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    I'll see if it's useful to add this to the property. At least at runtime this makes sense, I think.
     
  21. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
  22. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    See the 22_CGClonePrefabs example for a setup that places prefabs along a path. Add a ConformPath module to the virtual (green colored) path, just before the rasterization module (or the extrude module, if you want to extrude in the same process).
     
  23. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    Thanks for the information. It may come in handy some day, but I needed something sooner so I am using EasyRoads3D Pro for my race track creation now.
     
  24. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Curvy 2.1.2 Release notes

    • [NEW] Added CreatePathLineRenderer CG module
    • [NEW] Addressed Unity 5.5 incompatibilities
    • [FIX] SplineController.AdaptOnChange failing under some conditions
    • [FIX] Selecting a spline while the Shape wizard is open immediately changes it's shape
    • [FIX] ModifierMixShapes module not generating normals
    • [CHANGE] Changed 20_CGPath example to showcase CreatePathLineRenderer module
     
    red2blue and sjm-tech like this.
  25. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    77
    Hey there!

    I just updated Curvy to the latest version and it seems that it contains are some serious bugs :( (at least with Unity 5.5.1p3 which I am using right now)

    First of all I can't build my project for Android and second if you got to Edit->Preferences you are not able to click on the "curvy" section. Moreover it crashes the whole preferences window which needs to be closed and reopened to get it back to work.
    There are some more issues and they all throw the same exception which has something to do with the curvy dev-tools:

    It would be great if you can upload a fix for that!
     
  26. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    I've tested Curvy with 5.0.4, 5.5.1 and 5.6.0b6 and everything compiled and run fine. I recommend to delete the packages folder (/Curvy, /CurvyExamples, /DevTools) and reimport everything. Errors like that usually come from failed package imports, corrupted temp/library files and such.
     
  27. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    77
    Already tried that :(

    I even tried to del the whole library folder (hard reset of a project) with a complete new re-import of all assets. The problem is still there.
     
  28. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    77
    Alright, sorry for double-posting but I got rid of the problem. It had nothing to do with any plugin: Unity itself was it!

    I had to reinstall Unity and now everything works fine!
     
  29. Skolstvo

    Skolstvo

    Joined:
    Dec 21, 2015
    Posts:
    107
    Why are the splines using so many milliseconds of performance per Update frame? Even though they aren't doing anything? I have a scene where 30 percent of performance comes from BehaviourUpdate/CurvySpline.Update(). Also what's with all the garbage? I thought it was common knowledge that C# garbage collection in Unity is useless. Why create so many new variables in Update?

    Am I simply misinformed?
     
    N3V-Developer likes this.
  30. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    CurvySpline.Update() check's if a spline (or more accurate: spline segments) has pending changes and updates it's cache if needed only. So I guess you're either changing a spline or CP parameter each frame or CurvySpline.CheckTransform is enabled and you have tons of Control Points.

    And you're not misinformed in general, GC is slow, that's why we avoid feeding it. A spline doesn't feed the GC each frame. Updating/Refreshing caches do, but only creating as less garbage as possible.

    Feel free to start a thread in our support forum or contact me by mail to share some more details of your setup. I'm pretty sure we get this sorted.
     
  31. Skolstvo

    Skolstvo

    Joined:
    Dec 21, 2015
    Posts:
    107
    Thanks, that solved it.
     
  32. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    hello, i try to use curvy 2 using generator, but i watched the tutorial video, but i didn t manage to get 2 materials into one extrude tube. could u develop this matter ? i use the default template from the generator for this. i try to assign to the shape curve each point a different id playing with the uv values, but with no result. i use the latest version from the asset store.
    thanks
     
  33. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    i try to build for windows store, but i got this error
    Assets\Packages\DevTools\Extensions\Extensions.cs(1052,43): error CS1061: 'Type' does not contain a definition for 'IsGenericType' and no extension method 'IsGenericType' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)

    any idea?

    thanks
     
  34. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Sounds like you're using an older DevTools version. Please try delete /Assets/Packages/DevTools and reimport Curvy.
     
    toto2003 likes this.
  35. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Hey Jake,

    I want to move your packages folder of curvy 2.1.2 into my /Assets/_SystemTools folder.
    Is this save to do?

    thanks
     
  36. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Yes. But you might want to restart Unity afterwards to let Curvy find it's new "root" folder.
     
  37. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Hi Jake,

    Unity 5.6x produce about 25 Obsolete warnings with curvy 2.1.2. I have fixed the most by my self.

    The new Handles. function need an EventType.
    Handles.CubeHandleCap(id, position + direction * length, rotation, HandleUtility.GetHandleSize(position) * size, EventType.Ignore);

    Is EventType.Ignore correct?

    thanks.




     
  38. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Use EventType.Repaint!

    The good news: the updated version is ready to submit!
     
  39. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Thank you.
     
  40. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Did you updated from 2.1.2 to the new one on the asset store? It's still the same.
     
  41. milktoast

    milktoast

    Joined:
    Jan 29, 2014
    Posts:
    3
    Hey Jake,

    We are very interested in your plugin but before we purchase it we wanted to see if it is capable of doing what we need. We are building a game where the player needs to move in a 3D environment while following the path of the curve but rather than running directly on the curve the character controller needs to be running over a terrain and still be able to jump, fall into pits and run into colliders etc. Klonoa is a perfect example of the type of control we are looking to have. Thanks in advance for your feedback.
     
  42. vivalavida

    vivalavida

    Joined:
    Feb 26, 2014
    Posts:
    85
    Hi @Jake-L
    could curvy be used to make a flexible hose?
    if yes, could you point out how one might go about doing it?
     
  43. morepixels

    morepixels

    Joined:
    May 21, 2014
    Posts:
    18
    Hi,
    What is the best way to drag a 3D object with mouse/touch along a spline?
     
  44. N3V-Developer

    N3V-Developer

    Joined:
    Jun 7, 2014
    Posts:
    20
    Curvy has some issues at connection points. If the connection point lay in a curve and the spline controller move over the connection point then the controller yerks for a short time. I dived into the problem and the approximation table of the two last entries (near 1) have the same angle. This cause a bad movement at control points.

    Rotating handles at a connection of 3 splines unfortunately flips some of the handles into the opposite direction. Sync Rotation should take care of signed value of a handle L/R.


    Copy that. The spline controller spinning rotation create an late/fixed/update() and GC call per segment. This is a big performance issue on larger spline sets. It can be prevented by an option in your segment code.

    Moving a controller over a connection of more then 2 splines cause the controller to a unwanted flip while moving backwards sometime. The logic is buggy.

    The API GetAngle (or similar) returns wrong angles in some situations.

    Some basic stuff of curvy is buggy and need to be fixed or enhanced.
    Can you help plz?
     
    Last edited: May 19, 2017
    Quatum1000 likes this.
  45. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    This ran into different porblems, what happen if the mouse move over another spline?
    Does the object snap to the other spline? If not, what range the object should use, between control points, segments splines. From my side I would try GetNearestPoint() and clamp the result.
     
  46. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    When is this coming please? This post was just shy of two months ago, but according to the Asset Store I have the latest version and i'm still getting a crapton of warnings from Curvy and DevTools which are very annoying.
     
  47. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    For an unconnected spline this is expected, but connected splines should take care of that. Started a ticket to look into it.

    Could you elaborate? If I profile a SplineController I get exactly zero GC allocs, like it should be. What do I need to do to reproduce it?
     
  48. James-Williams

    James-Williams

    Joined:
    Aug 30, 2016
    Posts:
    26
    I have written a script that is attached to an Edys Vechicle which once enabled disables user input and begins moving the vehicle on a spline path. This works but there is a noticeable jerk when the switch is made.

    Am I right to assume that once the spline movement is activated the jerk is caused by the vehicle stopping to align itself and begin moving at the speed set by in the controller?

    Also, is there a way to have the vehicle continue with its current speed which is in fact matched up with the curvy movment speed with out the pause.

    The alignment part I have fixed by making the first point(0) and the second point(1) a child of the vehicle through script and once the switch is activated (sContoller.Play()) the points are then unparented and remain in place and the vehicle moves along the spline as needed.
     
  49. N3V-Developer

    N3V-Developer

    Joined:
    Jun 7, 2014
    Posts:
    20
    Attaching a spline controller to an object, an set the position I got the following warning
    in each Frame

    • SendMessage cannot be called during Awake, CheckConsistency, or OnValidate
    • UnityEngine.Transform:set_localRotation(Quaternion)
    • FluffyUnderware.Curvy.CurvyController:ApplyTransformRotation(Quaternion) (at Assets/Packages/Curvy/Base/CurvyController.cs:967)
    • FluffyUnderware.Curvy.CurvyController:applyPositionAndRotation(Single) (at Assets/Packages/Curvy/Base/CurvyController.cs:1218)
    • FluffyUnderware.Curvy.CurvyControllerPrepare() (at Assets/Packages/Curvy/Base/CurvyController.cs:736)
    • FluffyUnderware.Curvy.Controllers.SplineControllerPrepare() (at Assets/Packages/Curvy/Controllers/SplineController.cs:293)
    • FluffyUnderware.Curvy.CurvyController:OnValidate() (at Assets/Packages/Curvy/Base/CurvyController.cs:660)
    • FluffyUnderware.Curvy.Controllers.SplineController:OnValidate() (at Assets/Packages/Curvy/Controllers/SplineController.cs:272)
    • UnityEditor.SerializedObject:ApplyModifiedProperties()
    • FluffyUnderware.DevToolsEditor.DTEditor`1:RenderGUI(Boolean) (at Assets/Packages/DevTools/Editor/DTEditor.cs:153)
    • FluffyUnderware.DevToolsEditor.DTEditor`1:OnInspectorGUI() (at Assets/Packages/DevTools/Editor/DTEditor.cs:130)
    • UnityEngine.GUIUtilityProcessEvent(Int32, IntPtr)

    It does not take care before a connection. Here is a proof and example scene.
    Untitled-1.jpg

    Code (CSharp):
    1. using FluffyUnderware.Curvy;
    2. using System.Collections;
    3. using UnityEngine;
    4.  
    5. public class Check_T : MonoBehaviour {
    6.  
    7.     public CurvySpline Spline;
    8.     private IEnumerator coroutine;
    9.  
    10.     void Start() {
    11.         coroutine = WaitForSplineInitialized(Spline);
    12.         StartCoroutine(coroutine);
    13.  
    14.         // Spline.Refresh();
    15.  
    16.         // We want to access Segment-1 because error happens to the last and previous Approximation table index
    17.         // (O)-------------(1)============(2)
    18.  
    19.         int segment = Spline.ControlPointCount - 1; // Segment=2
    20.         segment -= 1;  // Segment=1
    21.  
    22.         var t_array = Spline.ControlPoints[segment].ApproximationT; // get Approximation table
    23.         Debug.Log("ApproximationT.length = " + t_array.Length);
    24.  
    25.         // Display
    26.         for (int i = t_array.Length - 5; i <= t_array.Length-1; i++) {
    27.             Debug.Log("ApproximationT[last-" + (i+1) + "] = " + t_array[i]);
    28.         }
    29.  
    30.     }
    31.  
    32.     IEnumerator WaitForSplineInitialized(CurvySpline Spline) {
    33.         if (Spline) {
    34.             while (!Spline.IsInitialized)
    35.                 yield return null;
    36.         }
    37.     }
    38.  
    39. }
    40.  
    1) WaitForSplineInitialized(Spline); does not work. It does not wait until the spline is initialized.
    If Spline.Refresh() de-commented it works. I'd like to wait as long as the splines are not Initialized in start()

    2) This example scripts display the tangent bug on the last index of the .ApproximationT[] field.

    3) What can I do against handle flipping bug of a connection, if at last 2 splines are connected?
    Can you fix this?
     
    Last edited: May 31, 2017
  50. Jake-L

    Jake-L

    Joined:
    Oct 17, 2009
    Posts:
    397
    Already answered by mail, but for everyone: you'll have to declare Start() as "IEnumerator Start()" in order to make yield work.