I've drawn a (2D)circle with a LineRenderer. Can I move that circle using code?

I’ve spent a lot of time on drawing a 2D circle using the LineRenderer. Now I want that circle to follow my character. Shouldn’t be that hard, right?

Well… I’ve tried parenting the component, I’ve tried synchronizing it with the position of the parent (see code below) but the circle stays where it is.

Can anyone please help me?

// Get the LineRenderer component
LineRenderer lr = transform.GetComponent<LineRenderer>();

// Draw the circle using that LineRenderer
DrawCircle(lr);

// Set the position
lr.transform.position = lr.transform.parent.transform.position;

And here is the DrawCircle() method:

void DrawCircle(LineRenderer lr)
{
	// Calculate each point (theta) in the circle
	// And set its position in the LineRenderer
	int i = 0;
	for(float theta = 0f; theta < (2*Mathf.PI); theta += theta_scale)
	{
		// Calculate position of point
		float x = (radCircle*100) * Mathf.Cos(theta);
		float y = (radCircle*100) * Mathf.Sin(theta);
		
		// Set the position of this point
		Vector3 pos = new Vector3(x, y, 1);
		lr.SetPosition(i, pos);
		i++;
	}
}

Alright, I already solved the problem. Stupid me forgot to uncheck the LineRenderer’s ‘Use World Space’ option.

You could modify the DrawCircle method to move ALL of the points to a new position, but I’m not quite sure why lr.transform.position didn’t work.

Looking at the code, you should check where the parent position is when you play it.