- Home /
Move pivot point in script
I need to be able to change the position of my gameObject's pivot point in code, but I can't seem to find a variable for this. Is it possible?
Answer by robertbu · Nov 13, 2014 at 10:35 PM
Modifying the pivot requires you to modify the vertices in the mesh. There is an editor script in the Unity Wiki that modifies the pivot:
http://wiki.unity3d.com/index.php?title=SetPivot
Look at the UpdatePivot() function.
Cool, thanks. $$anonymous$$ore complicated than I figured, though.
It might be simpler to just temporarily make it a child of an empty gameobject and use that as the pivot.
Answer by Kheremos · Nov 26, 2021 at 06:06 AM
It seems like most of the top results for this were overly complicated, what I did was this:
// Center Pivot
private Vector2 expandPivot = new Vector2(0.5f, 0.5f);
//method:
TMP_object.rectTransform.pivot = expandPivot;
So, basically, just get the rect transform and assign a 2d vector to it's pivot property. Necro posting because maybe this has changed in the last 8 years.