[Solved] LineRenderer affect Object pivot position

Yes… As simple as the title says!

  • Create a GameObject
  • Add LineRenderer component

Now pay attention to the object pivot! The pivot of the object move by the sum of the positions.
Example:

  • If you add only 1 position, then the pivot position (not the Transform position) will move to the value you set - if you set position 0 to (10, 0, 0), the pivot will be (10, 0, 0) and not the Transform position.
  • If you add more than 1 position, then sum all the vector3 positions and you’ll have the pivot position.

Why LineRenderer does that to the Object pivot position?
I kind have to create another GameObject (child of course) to avoid messing with the pivot position.

And again: LineRenderer positions affect the GameObject pivot position in the world. The PIVOT, not the transform position.

Devs, why?

I do not have this issue in Unity 5.4, changing or adding LineRenderer positions does not change the pivot. My Pivot is always at (0.5, 0.5) unless I manually change it.

I’m using 2018.1

you adding it to a object related to 2D (in your canvas).
Create a empty gameobject in the world not in your UI.

Since i’m using this example to simulate a bullet line and my GameObject uses mouseposition on plane raycast, the pivot being moved is messing with my raycast.

When I create a GameObject outside of a Canvas, it does not have a RectTransform, so it does not have a pivot. If I create a GameObject inside a Canvas and remove it from the canvas, setting it’s position values does not affect the RectTransform.Pivot value. Rotating my LineRenderer does not rotate the rendered line visual, so I’m not sure what other Pivot you could be referring to.

Sorry I am not able to download Unity 2018 right now

Ok, let me explain.
When you press W and select a GameObject in your scene, you will see those 3 arrows that represent the transform position, however, those arrows are called pivot (Handle if we hover the mouse over a certain button). In others 3D programs,they called it pivot.

There is a reason i said “Transform” and not “Rect Transform”. Either way… The handle move in the scene even though the transform position remains the same! I’m not saying that when you add 2 positions to the lineRenderer, your position will change. It doesn’t!!! That’s the issue!

The Image i uploaded shows that it maintain the handler at center position between all positions. the transform is at x:-5, the handler probably at x:-2.5, because there are 2 default positions.So:
Transform (-5, 0, 0), LR position 1 (0, 0, 0), LR position 2 (0, 0, 0), the Handler is at (-2.5, 0, 0).

Ok, I see what you mean.

By default, the list of positions you add to the LineRenderer are world space, not object space. To have your object’s transform affect the line positions, you must turn off the UseWorldSpace property on the LineRenderer component.

Turning off UseWorldSpace, work only if you have no positions in LineRenderer or if the positions is (0, 0, 0).
With UseWorldSpace off, it behave as if your object is scaled. The handler position (not the transform position) is not centered to the object anymore. This kills me because i cast a plane raycast to make the player GO look at mouse position. because the handler moves, the plane.raycast is fucked also.

I can usually understand what you’re saying, but I have a hard time understanding what you’re trying to do.

There are no objects in Unity that move the transform.Position when you add points or vertices. Adding positions to a LineRenderer is basically adding vertices to the line mesh you want to render, it would actually be very strange behavior if adding vertices to a mesh changed the transform position or the vertex positions to make the transform.position the center of them.

If you want your line to move based on it’s transform position and rotation, you have to not use world space on the line renderer. If you want that plus you want the transform position to be the center of your line, then you have to do some code work:

// Get the center
Vector3 totalPosition = Vector3.zero;
int numPositions = 0;
foreach (Vector3 pos in LineRenderer.Positions)
{
    totalPosition += pos;
    ++numPositions;
}
Vector3 center = totalPositions / numPositions;

// Move all points on the line so they are around the center
Vector3 centerOffset = transform.position - center;
for (int i = 0; i < LineRenderer.Positions.Length; ++i)
{
    LineRenderer.Positions[i] = LineRenderer.Positions[i] - centerOffset;
}

// Move the transform to where the center of the line was so it looks like the line didn't move
transform.position = center;

I’m still not sure exactly what you’re trying to do, so this may need some editing. This is mostly just to give you the idea that you’re going to have to do some math and code work to get this working the way you want.

Unity puts the transform tool either on the object’s pivot point, or on the average location of its hierarchy depending on which mode you choose. See this post, and confirm whether you have Pivot or Center selected.

3 Likes

Gambit-MSplitz, Nop. that’s not it. I thank you though for the effort on the help.

This!
The problem i was having was a dummy mistake i did when i setup the Ray variable and consequently i blame Unity behaviour. I completely forgot about this little button that toggle between pivot and center.

Thank you so much Gambit-MSplitz and dgoyette for the support.

3 Likes

For those of you who don’t know what this button is, they mean this one8762311--1187911--upload_2023-1-27_19-54-21.png.
Took me a while to figure that out sadly

2 Likes