Search Unity

[RELEASED] Curvy 2 - the ultimate spline solution

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

  1. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    1- About the Curvy Generator performance: I never noticed it because I always worked with a small number of modules. Now that I am aware of this, I will fix it in the next update. Until then, I have a quick fix for you. I will send it to you via PM
    2- About connecting modules: for now, and except connecting them through the UI, which can be tedious when having a lot of modules, the only other way is to use the API: cgModuleOutputSlot.LinkTo(cgModuleInputSlot)
    https://api.curvyeditor.com/520/cla...t_slot.html#aad0d70e5cfbc588445e935c4956961ab
    3- About the Range parameter: I will take a look at this tomorrow
     
  2. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    So if I understand your need correctly, you want the Range parameter to be set in absolute distance (between 0 and spline's length) instead of realtive distance (between 0 and 1), right?
    Right now, Shape Extrusion module does not take absolute distances for the Range parameter, but you can easily do that through the API: just create a script that takes two floats, defining your range in absolute distances, and the script divides these number by spline.Length to compute the relative distances, and assigns those values to the related fields in the Shape Extrusion module.

    Here is the code for it
    Code (CSharp):
    1. using FluffyUnderware.Curvy;
    2. using FluffyUnderware.Curvy.Generator.Modules;
    3. using UnityEngine;
    4.  
    5. public class AbsoluteRangeSetter : MonoBehaviour
    6. {
    7.  
    8.     public BuildShapeExtrusion ShapeExtrusionModule;
    9.     public float RangeStart;
    10.     public float RangeLength;
    11.     public CurvySpline Spline;
    12.  
    13.     void Start () {
    14.         UpdateRange();
    15.     }
    16.  
    17.     void Update ()
    18.     {
    19.         UpdateRange();
    20.     }
    21.  
    22.     void UpdateRange()
    23.     {
    24.         ShapeExtrusionModule.From = RangeStart / Spline.Length;
    25.         ShapeExtrusionModule.Length = RangeLength / Spline.Length;
    26.     }
    27. }
    28.  
    This script does the modification in play mode. You will need it to work in edit mode. I let you do that. Here is some useful documentation https://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html
     
  3. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
  4. wantondalliance

    wantondalliance

    Joined:
    Aug 22, 2018
    Posts:
    34
    I've got an issue with using Curvy - wondering if anybody could help. Apologies if I've posted this in the wrong place.

    https://vimeo.com/user9514265/review/334878880/47190ba5ac

    As shown in the video, I've set a Motor Controller to 'absolute', but the motor still seems to slow down at the spline handles. It's particularly noticeable at the second to last handle. I'm trying to get the motor's speed to be totally constant.
     
  5. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Hi,
    The link is not working. Are you sure you set Absolute to the Move Mode and not Position Mode parameter?
     
  6. wantondalliance

    wantondalliance

    Joined:
    Aug 22, 2018
    Posts:
    34
    Yes, both are on Absolute

    Here's the video:


    + FWIW I am working at 0.01 scale, perhaps this is causing issues? It's for physics reasons.
     
    Last edited: May 8, 2019
  7. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Hmm, I don't see an explanation for that. Can you please send me a reproduction scene so I can debug this?
     
  8. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Also, this reminds me that I haven't announce it yet:
    Curvy is on sale: -50% until May the 15th
     
  9. wantondalliance

    wantondalliance

    Joined:
    Aug 22, 2018
    Posts:
    34
    I've sent a packaged scene to you :)
     
  10. neferatum

    neferatum

    Joined:
    Apr 19, 2019
    Posts:
    2
    Hello, I have recently purchased the Curvy spline tools and the plugin is awesome..! I am trying to dynamically add the SplineController to the game object using AddController but I keep getting the following error:


    NullReferenceException: Object reference not set to an instance of an object
    FluffyUnderware.Curvy.Controllers.CurvyController.Initialize () (at Assets/Plugins/Curvy/Controllers/CurvyController.cs:788)
    FluffyUnderware.Curvy.Controllers.CurvyController.Start () (at Assets/Plugins/Curvy/Controllers/CurvyController.cs:537)


    Is there any function I need to run directly after AddComponent? or have I forgotten to set a variable?

    Thanks in advance.
     
  11. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Hi,
    Can you send me a reproduction scene so I can debug this?
    In general, you have to assign the Spline variable, like what you do when you create the controller through Unity's UI, but this doesn't seem to be the issue here.
     
  12. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    I attached a zip containing a scene and script that create at runtime a SplineController. The code is simple
    Code (CSharp):
    1. using FluffyUnderware.Curvy;
    2. using FluffyUnderware.Curvy.Controllers;
    3. using UnityEngine;
    4.  
    5. public class RuntimeControllerTester : MonoBehaviour
    6. {
    7.     void Start () {
    8.         SplineController splineController = gameObject.AddComponent<SplineController>();
    9.         splineController.Spline = FindObjectOfType<CurvySpline>();
    10.         splineController.Speed = 10;
    11.         splineController.Play();
    12.     }
    13. }
    Does this code work for you or does it generate the error too?
     

    Attached Files:

  13. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
    I feel like a dope but how come nothing shows up when i create control points. It gets added to the scene view but nothing renders????

    Never mind.
    Gizmos must be on in scene view. Duh
     
  14. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Hi,
    The spline does not render in Game view by default because not all users want to do display their splines.
    See the control points, and the spline itself, as just data. Each user will want to do something different with it. Some people will use a spline to make an object move along it, some other people will use it to extrude a mesh along it, both of which don't need to render the spline.
    If you want to render a spline, you can use a Curvy GL Renderer, like used in example scene 00_SplineController; or a Curvy Line Renderer like used in scene 04_PaintSpline.
     
  15. neferatum

    neferatum

    Joined:
    Apr 19, 2019
    Posts:
    2
    Hi,

    No, unfortunately this message is repeated, the spline is working though but the amount of messages is too large..

    Thanks a lot!
     
  16. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Hmm, that is weird. Can you please:
    1- tell what exact version you use
    2- tell me if you modified any source code of Curvy
    3- send me a reproduction case
     
  17. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    rrahim and Arkolis like this.
  18. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    704
    Hi, I'm profiling to optimize my game and I find that Curvy is using about 0.2ms running Train sample. It doesn't seem a lot but it represents about 10% of the whole CPU cycles used up by Curvy if you exclude Camera.Render.
    I would like to know if this is normal since all it's doing is following a spline path.
    upload_2019-8-12_22-23-16.png

    Also, I find that ScanConnections() is getting called about at every 1/10 of seconds while "Playing" and in turn, it's calling GameObject.FindObjectsOfType<CurvyConnection>() which is quite expensive operation. It's Editor only event but it doesn't seem necessary to call whenever "hierarchyChanged" event is fired, instead check only at the Start or something.

    Thanks.
     
  19. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Hi,

    1- Curvy controller can probably be further optimized. I will give it a try later this week. Just so I can get an idea about your target, how much ms do you expect Curvy to take?
    In my attempt, I will of course try to optimize the controllers while keeping the same features, so that it can be used by everyone. But, if you don't use connections nor events with your controllers, I can send you a custom version of the controller's code that does not support these features, and that will use way less CPU time. Also, what kind of Clamping do you need with your controllers?

    2- In my tests, ScanConnections is not called often, so I assumed that it calling FindObjectsOfType should not be an issue.
    Based on hierarchyChanged's documentation, "Actions that trigger this event include creating, renaming, reparenting, or destroying objects in the current hierarchy, as well as loading, unloading, renaming, or reordering loaded Scenes. Note that the event is not raised immediately in response to these actions, but rather during the next update of the editor application."
    So it should not be called that often when playing. Can you tell me what is your use case that made it be called every tenth of a second?
    Checking only at Start (or similar) will not do the intended effect because objects created after the Start method will get ignored. I need something that will be checked at each creation and destruction of an object. Maybe there is a better way than hierarchyChanged, but before starting to look for something else, I need first to read your answer to the above question.

    Thanks and have a nice day
     
  20. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    704
    Hi, thanks for the quick reply.
    I don't have specific target optimizations but asking if that's normal. Right now, Train sample is pretty simple path-following example yet it uses quite a significant portion of the whole CPU cycle.
    I'm not sure I should use Curvy for the runtime path-following. Curvy is very nice for creating path objects but may not as efficient as other simple path-following solutions.
    How about superfast path-following option if all I want is simple spline path-following during runtime without complicated features? I think it will be useful in many situations and make Curvy more useful. Otherwise, I might have to have another spline solutions and I hate to have two similar solutions in a single project.

    I have objects, for example, such as bullet shell, particle effect is triggering the hierarchy changes. If Start is not an answer, perhaps CurveyConnection to register itself to the list might be a better approach, I think. ^^
    Cheers!
     
  21. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    704
    Here is one more optimization issue. Having prefab is much more desirable for efficient memory and fast rendering. For example, GPUInstancer requires prefab in order to take advantage of instancing. However, Curvy always converts to non-prefab and I have to manually change them to prefab after Curvy generates GameObjects.

    The following image is from the same Train example. I created a prefab and gave the prefab as an input, but it turns them into GameObjects. If the input is a prefab, the end result should be prefab. Having GPU Instancing (it will render 1000s of GameObject in a single drawcall) will make the train example to run about twice as fast in my test.

    Thanks.

    upload_2019-8-13_2-55-31.png
     

    Attached Files:

  22. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Thanks a lot for finding those optimization suggestions. I will work on this this week, and provide you with an optimized version. I will then add them to the next update
     
    chrisk likes this.
  23. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
  24. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Hi, is there a way to preview where an item is going to be at a particular time when using a spline to control an object's motion? Or, if not, is there a way to somehow "bake" an object's motion from a spline to a legacy Unity animation?

    I've been playing with an older asset called Cinema Director. It's set up to be able to extend its capabilities with your own code, so I've been adding some elements that can be controlled on its timeline.

    Curvy would be handy for animating the paths of some spaceships during cutscenes, but it's difficult to sync up the motion with other camera motion, camera changes, and other events that way. It'd be ideal if there was a way to programmatically control a preview of where the GameObject will be at a particular time. Then I could add integration with Cinema Directory to line everything up.

    That asset also supports Unity animation, so an alternative that could still be useful would be to bake a curvy path to an animation and see the preview when scrubbing back and forth on the timeline that way.
     
  25. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Hi,

    Sorry for the late answer, I was on vacation.

    A controller has a Position property (and associated m_Position field) which is a float that defines where the object is on the spline.That property can be set via inspector, API or Unity animation.You can learn more about it in the API and script documentations.

    When a controller plays, it basically just updates that Position property accordingly to the elapsed time and the controller's speed. It's simple maths. And then based on that value the actual 3D position of the object's transform is computed. So you can do that math to know what value Position will have at a specific time, set that value and see where the controller's object will be positioned. You can also not play the controller, and update yourself at each frame the Position property value.

    Did my answer solve your issue?
     
  26. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    Yes, I think you answered my question.

    I take it I could do something like this:

    1. Use a SplineController and set PlayAutomatically to false.
    2. Do the math to determine what relative "position" I'm at on the spline (from that other asset's timeline) by setting the Position float.
    3. At that point, the SplineController will go ahead and set the target object's transform, right?

    That Cinema Director asset does give you a local time offset per "clip", so it sounds like that would be pretty doable, if I have that right.

    Thanks for the reply! That could be super useful.


    EDIT: OK, I finally got a minute to look at this, and it was even easier than I imagined.

    That cinematic asset has a method in its CinemaActorAction class that you can inherit from called UpdateTime with runningTime passed in (where you are in the clip). Plus you have access to an ancestor property called Duration that is the clip length. So I created a new class for SplineController integration with Cinema Director.

    In UpdateTime, it was literally this sort of thing:

    mySplineController.Position = runningTime / Duration;

    It works EXACTLY as I had hoped. I can scrub the timeline back and forth and see where my spaceship is at any point, which makes it super easy to line up cool shots with the cameras.

    Thanks again for the info!
     
    Last edited: Nov 3, 2019
    rrahim likes this.
  27. rrahim

    rrahim

    Joined:
    Nov 30, 2015
    Posts:
    206
    Based on the work @Steve-Tack is working on, is it possible to have a similar integration with the Unity Timeline?
    Or is this already there and I've missed it?
     
  28. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Hi,
    Compatibility with Unity Timeline is already there: the "Position" field I spoke about in my earlier post can be animated through the Unity Timeline

    upload_2019-11-6_12-5-19.png
     
    rrahim likes this.
  29. rrahim

    rrahim

    Joined:
    Nov 30, 2015
    Posts:
    206
    Excellent! I've just started work on an implementation that would need this and I'm glad it's there. I'm guessing I would have to add the position field to the timeline and animate the value from 0 - 100% to get a linear movement, and the ability to scrub across the timeline.
     
  30. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    That's the idea. Glad to see that this feature was helpful.
     
    rrahim likes this.
  31. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Hello, I have noticed recently that Curvy is forcing the Unity Editor (2019.2.10f1) to update every frame, making my CPU run very hot on idle and wasting battery on my laptop. It's making the editor run at full single core speed when the editor is in focus and sometimes even when the editor is not in focus!
    The only way to prevent this is by disabling any gameobject with a Curvy component in it or by minimizing the Unity Editor.
    I don't know if this is due to any recent Unity change, but it's making my room HOT while working on my scenes.
    Any quick way to try to fix this @Aka_ToolBuddy ?
     
  32. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Just to clarify the previous post: this is happening without selecting any Curvy object (but with Curvy objects in the scene) and with the Curvy UI disabled.

    Actually I think the problem is in the Curvy Spline Controller. (Splines don't spam the CPU. Only objects controlled by them.)
     
    Last edited: Nov 6, 2019
  33. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Can you please send me any scene that has this issue?
     
  34. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    That's really weird: I'm trying to make a repro project for this behaviour but I can't replicate it on an empty project.
    Even weirder, in my current project, the amount of CPU usage depends on the amount of gameobjects present in the scene. So the more objects I have on the scene (not related to curvy), the more it eats CPU on idle.
    One could think th problem is not related to Curvy, but the fact is this behaviour stops as soon as I delete the only 2 gameobjects that have a Curvy controller.
    As soon as the Curvy Spline Controller components are deleted, my CPU usage at idle falls to 0%

    Also I have noticed that having a Curvy Spline Controller in my current project makes the Editor update as if "animated materials" was set to ON, making my materials animate, even though "animated materials" is currently set to OFF.

    Do you have any idea of what could be going on?
     
  35. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Ok, I found how to replicate it on a clean project:
    You have to set the vsync OFF to notice the CPU consumption. Otherwise it's not visible on fast systems.
    But the fact is Curvy is forcing the Editor to update each frame, and that's what causes the issues.
    Also, the more objects in the scene (without Curvy components) the more it eats CPU cycles.
    I'll send you the repro project by private message.
     
  36. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Hi,
    To keep everyone up to date: the issue was found, a hack was send to atomicjoe, and proper fix should be included in the next update.
    The issue was introduced with Curvy 5.1.0, and happens with Unity 2017.2 or newer. It basically makes the editor, in Edit mode, update frequently like in Play mode, which might consume a lot of CPU in complex scenes.
    Sorry for the inconvenience
     
    hopeful and rrahim like this.
  37. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    If anyone is having this issue, in the mean time, enabling Vsync in the project preferences mitigates it a lot.
     
  38. AnthonyPaulO

    AnthonyPaulO

    Joined:
    Nov 5, 2010
    Posts:
    110
    Hey guys,

    I'm interested in using Curvy for laying train track and was wondering if it supports the use-case of allowing the user to lay their own splines at runtime similar to the way you would do so in the editor, with control points. Is there support for this type of manipluation in the api?

    Thanks!

    Anthony
     
  39. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Hi,
    You can lay splines at runtime through the API, but you will have to code your own runtime UI that links users actions to the API calls.
    Here is an old example doing that. Please keep in mind that runtime generation duration was greatly reduced since the version of Curvy Splines this application used:
     
    AnthonyPaulO and atomicjoe like this.
  40. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    WOW, this app is really neat!
     
    Aka_ToolBuddy likes this.
  41. AnthonyPaulO

    AnthonyPaulO

    Joined:
    Nov 5, 2010
    Posts:
    110
    Wow... I gotta say, that's a pretty cool app!
     
  42. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    @Aka_ToolBuddy Did you ever figure out how to extrude tunnels around a spline that has splits and clear out the interior like a proper tunnel intersection?
     
  43. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Sorry but no. If you find a way I would be interested in it.
     
  44. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    If I had to suggest something quickly, I would said:
    Given two hollow tubes, A and B, and the two equivalents non-hollow tubes A' and B'
    I think the result would be the union of the following meshes:
    • intersection of A and B
    • A minus B'
    • B minus A'
    I might be wrong, haven't give this a long enough thought
     
  45. park007

    park007

    Joined:
    Nov 7, 2019
    Posts:
    4
    I want to know how to get position of spline at every frame, somebody knows?If you know,teach me.Thank you very much.
     
  46. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Hi,
    What fo you mean by position of spline? Is yourSpline.transform.position what you need?
     
  47. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Also, Curvy is on sale: -40% until Friday December 12 at 23:59 PT
     
  48. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    atomicjoe likes this.
  49. AnthonyPaulO

    AnthonyPaulO

    Joined:
    Nov 5, 2010
    Posts:
    110
    FYI, the checkbox to switch train to Junction in the train demo isn't working.
     
  50. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    Hi,
    Thanks for letting me know.
    I can't reproduce your bug. This checkbox is part of my pre-release tests, so I am positive that I was able to tick it before pushing any new release. Sometimes the checkbox is tricky to check while the camera is moving. Maybe this is what is happening to you. If not, can you please send me a reproduction case?
    Have a nice day