Posts: 4
Threads: 1
Joined: Feb 2024
Hello,
Loving the tool so far, but I am wondering if there is a way to avoid GC allocations on control point position changes at runtime?
I am trying to match a spline with 'anchors' I have on a moving object and currently using the following code in update:
Code:
controlPoints ??= wormRail.ControlPointsList;
for (int i = 0; i < anchors.Count; i++)
{
controlPoints[i].SetPosition(anchors[i].transform.position);
}
But this is incurring ~1.2KB GC each frame (8 control points). Is there a way to update spline control points at runtime without GC allocations?
Thanks,
Elliott
Posts: 2,113
Threads: 92
Joined: Jun 2017
Hi,
I tried to reproduce your result but couldn't. Here is a script I attached to a spline:
using FluffyUnderware.Curvy;
using UnityEngine;
public class tesT : MonoBehaviour
{
void Update()
{
var controlPoints = this.GetComponent<CurvySpline>().ControlPointsList;
for (int i = 0; i < controlPoints.Count; i++)
{
controlPoints[i].SetPosition(Vector3.forward);
}
}
}
At runtime, there were no allocations from this script. Can you please profile with the Deep Profiling option, and then send me a screenshot of the memory usage of the problematic Curvy Spline method(s)?
Thank you
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 4
Threads: 1
Joined: Feb 2024
Hello, apologies for the late reply- not been able to work on this for a bit.
Seems to happen in CurvySpline Refresh. Also getting allocations in the generator- I assume that is because I am moving extruded splines. Is it possible to avoid allocations on that too? Not too bad if not as I can work around it. The main thing I need is the spline to match, so good to know that should work without allocations.
If I disable the extrusion, and comment out:
Code:
controlPoints[i].SetPosition(anchors[i].transform.position);
No more allocations. If I use that line with the extrusions disabled, still allocations. If I move the spline from child of the generator objects, no allocations. So I assume spline is still finding the components and doing something, even if disabled?
Posts: 2,113
Threads: 92
Joined: Jun 2017
Hi again,
No need to apologize.
Can you send me a reproduction case?
Thanks
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 4
Threads: 1
Joined: Feb 2024
Sent you a message with an example project showing what I am (roughly) trying to do, with the allocations happening. Thanks.
Posts: 2,113
Threads: 92
Joined: Jun 2017
Hi
I worked on your example. I managed to reduce the allocations made by a spline update to 160B. I will keep working on it in the coming days, to hopefully produce a solution with 0B allocations.
Removing allocations made by a curvy generator update will take significantly more time.
I will keep you updated.
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.
Posts: 2,113
Threads: 92
Joined: Jun 2017
Hi,
I managed to reach 0 allocation. This optimisation will be part of the next update.
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.
Posts: 4
Threads: 1
Joined: Feb 2024
That's amazing. Thanks so much for the support. Seen your PM also so will apply that. Appreciate it!
Posts: 2,113
Threads: 92
Joined: Jun 2017
You are welcome, my pleasure
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.