Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Feedback Splines and using them for content generation

Discussion in '2022.1 Beta' started by evyatron, Apr 3, 2022.

  1. evyatron

    evyatron

    Joined:
    Jul 20, 2014
    Posts:
    132
    First of all I'd like to say I'm really enjoying the new Splines - I think they mostly work really well and are very easy to work with!

    Having worked with them for a bit, I do have a few suggestions though:

    SplineContainer
    1. SplineContainer should have a "changed" method. This is because you usually want to use the container to properly take its transform into account, however if anything changes its underlying Spline - your "spline.changed" listener gets invalidated. If we had SplineContainer.changed which would invoke either if the underlying Spline changed OR if a new Spline had been assigned - that would solve that. This also breaks current Unity components like SplineInstantiate btw - I have a component that assigns a new Spline to a SplineContainer, and the relevant SplineInstantiate don't update automatically.
    2. SplineContainer can have caching. Since a lot of code often requests the values at the same distance along a spline, performance can be much better by just caching it. You can give users the option to maybe tweak the accuracy of the caching (X decimal points).
      This can greatly improve performance in components such as "extrude mesh along a spline" - any vertices that fall on the same distance along the spline would have a O(1) for getting their values.
    Spline Editor
    1. Automatically activate when selecting a spline object in the hierarchy. I don't know if this is a Spline-specific issue or a global Unity Tools thing, but as it stands when selecting a spline the only indication I have is a line turning blue to yellow. I then need to find that spline button in order to actually edit it. Why not enter edit mode immediately when selecting a Spline :)
    2. When selecting a knot or tangent, allow dragging it on mouse down. Currently you must first select it with mouse press, and only then you can actually move it around.
    3. [Error] Sometimes when editing splines you get IndexOutOfRangeException in the gizmos drawing. I couldn't really pin down when it happens though. [see image] upload_2022-4-3_10-34-11.png

    Suggestion - add a new SplineGenerator base component to allow coders to create spline-based content generators. I initially thought that's what SplineComponent was but apparently not.
    This was one of the first things I did when setting it up (see attached file, happy to share) and it really speeds up creating any such components people might want to add. It also takes away a lot of the boilerplate stuff needed to do it.
     

    Attached Files:

    NotaNaN, URocks, JoNax97 and 3 others like this.
  2. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    552
    Thanks for taking the time to give us this feedback.

    Yes, this is a good point. In the editor we are usually using `EditorSplineUtility.afterSplineWasModified` to register for any Spline change, then filtering based on the relevant targets. Adding a local callback on the MonoBehaviour would be nice to have in the runtime.

    In most cases, the expensive calculations are already cached. The `Spline` class is responsible for implementing caching, where `SplineContainer` is existing only to transform the results into world space. The exception is when the transform is non-uniformly scaled, in which case the functions are required to bake the spline data when evaluating.

    This is a broader tools workflow question. It's one we have gone back and forth on internally. Tool contexts are still a very new feature, and I expect the UX will be changing more in the future.

    In the initial offering, we decided not to automatically force the tool context. In general we try not to be too "smart" about guessing user intentions. However we are aware that discoverability is an issue, and will likely continue iterating on this design as it matures.

    Definitely, this is high on our list as well.

    We're refactoring much of our tool code for the next update, I suspect this is already fixed.

    What would you expect this class to contain? Is there an example in the Samples that illustrates this?
     
    NotaNaN and LeonhardP like this.
  3. evyatron

    evyatron

    Joined:
    Jul 20, 2014
    Posts:
    132
    Thanks for the answers!

    Nice, thanks!

    Hmm so something might not be working there? I don't have any scaling, but I added my own caching and it seems to have improved performance significantly! What I do is convert the float distance-along-spline to an int with a certain accuracy, and cache all the relevant outputs - position, tangent, up. This helps massively when doing mesh extrusion for example - if you have a cube you extrude along a spline, instead of evaluating 6 points, you only evaluate 2.

    You can see my attached code - it's basically a base abstract class you can use to easily generate things with Splines. So all you as a class user needs to implement is a) which values invalidate your output, and b) the actual generation method. So it hides a lot of boilerplate change events and hash checks.
     
  4. yahodahan

    yahodahan

    Joined:
    Apr 26, 2009
    Posts:
    1,380
    Hi! A bit more on this one - if Splines were built to only have simple controls, like Light (simple non-selectable handles that can be dragged), automatically activating would work fine, yes. However, Splines are more like a full 3D mesh, with selectable sub-elements (points, tangents, eventually segments and others perhaps). So activating automatically would be similar to ... selecting a cube in Blender/ProBuilder/3DSMax, and suddenly being pushed into edit mode. That would be bad for sure.

    Consider also, apps like Photoshop, Figma, Illustrator - selecting the Spline allows manipulating it as a whole, then a separate tool or edit mode enables element editing.

    However ... you can always use the "Edit" shortcut to instantly jump in/out of editing the selected Spline :) (this will also work for other editable objects, as those are developed).
     
  5. evyatron

    evyatron

    Joined:
    Jul 20, 2014
    Posts:
    132
    Hmm thanks for the context - I would say this might make sense from a "product" point of view, however from my past experience in teams working with splines (and me working with this for a couple of weeks now) - you almost always want to edit the Spline itself as quickly as possible :)

    Actually moving/rotating the game object itself is usually secondary.

    Could that be exposed to users? On a per-tool basis. So I could say "automatically turn on Splines tool" but not...other things.
     
    myanko likes this.
  6. yahodahan

    yahodahan

    Joined:
    Apr 26, 2009
    Posts:
    1,380
    Sure, I imagine it could be done that way! We did have the same request from one of the internal testers. So, sure it could work as a per-type toggle, ie when I select a ProBuilder mesh, it doesn't auto-edit, but when I select a Spline, it does.

    However, have you tried with the shortcut for editing? That might be a good middle ground. You can customize that shortcut to whatever you like of course, via the Shortcut Manager - maybe even something real easy like "spacebar".

    For reference, that "Edit" shortcut/method will be used pretty heavily in the future, as tools begin to take advantage of it (internal and asset store/custom).
     
  7. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    727
  8. Ofx360

    Ofx360

    Joined:
    Apr 30, 2013
    Posts:
    155
    Would it be better to represent the knots and handles as balls or square? Because at the moment its pretty hard to manage in 2D since all the gizmos virtually disappear in that view.
     
  9. evyatron

    evyatron

    Joined:
    Jul 20, 2014
    Posts:
    132
    I did - it's certainly much better than moving the cursor to click that small button :) However it's still an extra thing to do, creating friction when working with splines.
     
  10. timashroll7

    timashroll7

    Joined:
    Jul 22, 2022
    Posts:
    1
    hi there, wondering if someone could tell me the actual shortcut for editing splines?? I cant find it in the shortcut manager , thanks in advance
     
    morepixels likes this.
  11. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    I was also looking for this - 'Cycle Tool Modes' seems to be the shortcut you're looking for.