Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Avoiding runtime GC allocations on control point position change
#1
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
Reply
#2
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 will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
Hello, apologies for the late reply- not been able to work on this for a bit.

[Image: JE7QFbO.png]

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?
Reply
#4
Hi again,
No need to apologize.
Can you send me a reproduction case?
Thanks
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
Sent you a message with an example project showing what I am (roughly) trying to do, with the allocations happening. Thanks.
Reply
#6
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 will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#7
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 will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#8
That's amazing. Thanks so much for the support. Seen your PM also so will apply that. Appreciate it!
Reply
#9
You are welcome, my pleasure Smile
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How could I get position in spline from "From" value in BuildRasterizedPath? Chanon 1 6 02-12-2024, 09:54 PM
Last Post: _Aka_
  Finding relative position across connected splines DekoGames 1 5 02-05-2024, 10:11 PM
Last Post: _Aka_
Wink Modifying Splines at Runtime artsung 1 4 01-30-2024, 09:40 AM
Last Post: _Aka_
  Is it possible to create a road texture at runtime? artsung 1 3 01-30-2024, 09:30 AM
Last Post: _Aka_

Forum Jump: