Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

SplineMesh, the plugin to create curved content

Discussion in 'Assets and Asset Store' started by methusalah999, Dec 14, 2017.

  1. ChrisRapczynski

    ChrisRapczynski

    Joined:
    Jan 13, 2020
    Posts:
    36
    for some reason this is what Im getting. I attached the script, maybe I added the lines wrong?
    upload_2023-2-23_20-14-22.png
     

    Attached Files:

  2. ChrisRapczynski

    ChrisRapczynski

    Joined:
    Jan 13, 2020
    Posts:
    36
    upload_2023-2-23_22-16-5.png upload_2023-2-23_22-16-30.png
    I made sure the decal went the same length as the rail itself in blender and it worked perfectly! thanks for the help there! This is a massive boost in asset creation and unity work flow. It'd be great if I could get your repeat stretch code working because that'd be the last step. I cant see where the scale value would actually affect the scale, it seems like it only gets implemented in determining the distances of each mesh apart from each other
     
  3. ChrisRapczynski

    ChrisRapczynski

    Joined:
    Jan 13, 2020
    Posts:
    36
    I switched
    float distance = (vert.position.x - source.MinX + offset) + scale;
    for
    float distance = (vert.position.x - source.MinX + offset) * scale;

    and also removed
    offset += source.Length * scale;
    and this is the result:

    it seems to have gotten it working! thanks so much for this this is so cool! it has an error where seemingly at the exact length where the gap would be 0 anyway it throws out upload_2023-2-25_12-47-5.png
    I'll try to look into this but for the most part its doing exactly what I need! thanks again this is so cool
     
  4. ChrisRapczynski

    ChrisRapczynski

    Joined:
    Jan 13, 2020
    Posts:
    36


    The flickering in and out issue seemed to be a similar floating point issue that I had experienced when I was trying to find a gap clearing solution. I fixed it by changing
    offset += source.Length;
    to
    offset += source.Length - (.000001f);
    there is an issue where when the scale x is smaller than .1 so Im sure theres a smarter way around this but I dont think I'll ever scale an object that small on a spline so I'm gonna call it done.

    and as you can see the decal spline followers sync up perfectly. thank you so much methuselah 999, I really didnt think I'd get this working. In my source comment when I said I deleted a bunch of complaining, part of it was how issues with 2dspriteshape killed my interest in a 2d project so this really was a lifesaver. Heres the altered meshbender script for anyone that's interested in doing something like this
     

    Attached Files:

    methusalah999 likes this.
  5. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    10
    When I edit a node's scale in the Showcase scene, I can see the Spline Extrusion updating in real time. But when I do it in another scene, it doesn't update in real time as I change the value. I have to deselect the object and select it again for it to take effect. Why is this happening? Am I missing something?
     
  6. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    620
    To be updated during play time, in the SplineMeshTiling you need to check "update in play mode".

    If you wrote your own component, you will have to check that you didn't set your generated as static, or they will be batched with the rest of the static elements of the scene and won't be modifiable.
     
  7. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    10
    Sorry. I think I wasn't clear with my problem. I have a gameobject with the Spline component and Spline Extrusion. I don't need it to update in play mode.What I meant was that I needed to update in edit mode as I change the values from the inspector. I can modify any value from the inspector but the changes won't show unless I deselect the object and select it again. But this isn't the case in the Showcase scene. In that scene I was able to modify any value and see it reflected in the scene view instantly. So that's why I'm wondering if I'm missing something in my scene.
     
  8. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    10
    Is there a way to change the layer of the meshes generated by Spline Extrusion? If I change them, they just revert to Default when entering play mode.
     
  9. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    620
    I though there were a logic to make the generated objects having the same layer than the parent but I don't find it in the code. However, you can simply add a line in SplineExtrusion.GenerateMesh with
    go.layer = gameObject.layer;
    , something like that.

    Please remember that SplineMesh is designed so you can (and should) expand it whenever you have some specific needs. This is because splines can be used in a huge variety of ways and use cases. I preferred this approach instead of very complexe component offering tons of options. The code of the high level API is designed to be very simple and I encourage you to copy/paste the SplineExtrusion as a MySplineExtrusion script and change it to fit your needs.
     
    jRocket likes this.
  10. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    10
    Is there an easy way to modify the ExampleSower script so that the prefab isn't generated in some segments of the spline? I'm using it to place trees along a river. But at one point I have a waterfall and don't want trees to be generated along the vertical part of the waterfall.
     
  11. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    620
    Sure thing, you just have to add a test whether or not the object should be generated in the loop, using the rules you want.

    For example here, I only generate a pillar if there is not road below https://twitter.com/methusalah0/status/1087493276863737857
     
  12. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    10
    How could I make it not generate the object when the path goes down the waterfall? I'm sorry, I'm kind of a beginner..
     
  13. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    620
    For example, here in the code, if the CurveSample is too close from a waterfall, you just continue to the next iteration.

    Code (CSharp):
    1. while (distance <= spline.Length) {
    2.     CurveSample sample = spline.GetSampleAtDistance(distance);
    3.  
    4.     if(/*sample is far enough from all waterfalls*/){
    5.         GameObject go;
    6.         go = Instantiate(prefab, generated.transform);
    7.         (...)
    8.     }
    9.     distance += spacing + UnityEngine.Random.Range(0, spacingRange);
    10. }
    Please remember that ExampleSower is only an example. It is strongly advised to only take inspiration from the example code and write your own.
     
  14. rafael_unity386

    rafael_unity386

    Joined:
    Jun 15, 2022
    Posts:
    10
    I noticed that on the Showcase scene, nothing will update outside of Edit mode unless I have 10 - Spline enabled. That has the Example Follow Spline script. What does that script have that allows the splines to update in edit mode and how can I add that to my own scripts?
     
  15. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    620
    When the game is not playing, there is no game loop running. You can still have a constant refresh of the editor with two conditions. First you need to have the attribute [ExecuteInEditMode] on your MonoBehavior class, and you need to ask the scene window to "always refresh" by selecting the option in the post-process menu at the top right corner.

    The 10th example forces the scene window to refresh because it makes it dirty as often as possible so whenever it is activated, the scene will refresh even if you didn't select "Always refresh".

    All SplineMesh Example are designed to refresh this way in the editor without the game running, so that you can test things and see the result right away. But this is not a best practice for your actual project at all and I would advise against it in most situations:
    - it will put your CPU at work constantly,
    - it will change the serialized data of your scene and prefabs and force you to save again constantly,
    - it may cause various issues in the prefab editor,

    It's generally better to react to data changes instead, like with OnValidate method.