Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spline.length incorrect
#1
Question 
Hi, so I'm  creating a sort of road system where I 1st click to set the start of the spline ( CP0000) , I keep mouse button down and buttonup places  the 2nd control point etc.
  After each control point is addded I'm  logging the spline.length but what I've noticed is the spline length isn't correct. It's correct in the inspector but  not when I log it. 
The Gameobject that the spline is a part of is always at 0,0,0.  What I have noticed is after the 2nd control point is added (CP0001) ( this is when I log the spline.length ) the spline length is logged as the dist between 0,0,0 and the CP0000 regardless of how long the spline actually is.
  If I place the Gameobject at the position of CP0000 after placing CP0001 the spline.length is logged as 0 but it's still correct in the inspector.

1. How can I get the acutal spline length please ?
2. Is there a way to get the spline length at each control point.


Regards.
Reply
#2
When a spline is modified, a call to Refresh is needed to update some of its data. This call is done automatically every frame, and in some API methods. Under some circumstances, one might call the Length property while the spline is not refreshed.
Try calling spline.Refresh before doing the log. If the problem persists, please send me a reproduction case (the code doing the cp adding and logging)
I hope this helped
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#3
Refreshing the spline solved it, thanks.

Sorry for another question but is there a way to get the length at each control point apart from logging spline.length in a list

Cheers.
Reply
#4
You are welcome

yourSpline.TFToDistance(yourControlPoint.TF)

Have a nice day
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extrude mesh along spline. New and confused user GhostStalker 3 7 01-02-2025, 09:58 AM
Last Post: _Aka_
  Newly created spline is invisible quickytools 7 19 12-21-2024, 10:14 AM
Last Post: _Aka_
  Method of scattering objects along spline joebain 1 3 11-26-2024, 03:20 PM
Last Post: _Aka_
  Curvy Line Renderer for UI Spline? gekido 5 13 10-29-2024, 10:19 AM
Last Post: _Aka_

Forum Jump: