Hey everybody,
I’m been trying to get a trail renderer to work with a floating origin system I’m implementing and pretty sure I’ve come across a bug in SetPosition. My Unity Version is 2022.3.14f.
Whenever I call SetPosition(), the trail renderer seems to be correctly setting the positions of all the vertices, but the visual trail itself doesn’t seem to be correctly displaced. I think the trail renderer is still rendering the trail at the previous position, making it incorrectly renderer a line at that point to its new position. You can see the effect on the image below:
I debugged this by spawning an object at each of the trail vertices after SetPosition() and they’re in the right place.
Here’s a picture of the trail renderer’s visuals after SetPosition is called. They’re in their original position - i.e. not having been shifted along with the vertices.
Here’s my offset function:
void TrailOffset(Vector3 offsetPosition)
{
foreach (TrailRenderer trailRenderer in trails)
{
int trailSize = trailRenderer.positionCount;
Vector3[] positions = new Vector3[trailSize];
trailRenderer.GetPositions(positions);
if (positions.Length > 0)
{
for (int i = 0; i < positions.Length; ++i)
{
positions[i] -= offsetPosition;
}
}
trailRenderer.SetPositions(positions);
trailRenderer.GetPositions(positions);
//DEBUG
for (int i = 0; i < positions.Length; ++i)
{
Instantiate(debugObject, positions[i], Quaternion.identity);
}
}
}
Has anybody run into something similar or knows if this is intended behaviour? Really would appreciate any help there is, as this is the last thing I need to fix up before a floating point implementation is good to go.
Thanks!


