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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to generate gameobject on the control point Yang Yi 0 1 Yesterday, 11:43 AM
Last Post: Yang Yi
  Getting Distance from a World Point zorksox 3 5 04-16-2024, 07:30 PM
Last Post: _Aka_
  Set Volume to the Volume Controller at Runtime pako88 2 14 04-08-2024, 03:26 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 9 03-28-2024, 10:08 PM
Last Post: _Aka_

Forum Jump: