- Home /
Get the position of a RectTransform relative to Canvas
Hi,
I'm trying to get the relative position of a RectTransform to Canvas, but it always gives zeros values. I'm using Vertical's Layout in the parents.
How can I get the values that can see in the RectTranform of the gameobjects.png capture?
Thanks and grettings!!
Answer by xxmariofer · Mar 15, 2019 at 02:44 PM
hello thats because the verticallayoutgroup doesnt update till end of frame you can use the start event as a corroutine and break till end of the frame
IEnumerator Start () {
yield return new WaitForEndOfFrame();
Debug.Log(GetComponent<RectTransform>().anchoredPosition);
}
Yeah, this solution works perfectly! I previously used this solution to get the size of a RectTransform, but I didn't think in use for this purpose. Thanks!
Your answer
Follow this Question
Related Questions
How do I get a RectTransform position relative to another that is not the parent? 0 Answers
Change position of a text prefab added to a world space canvas via scripting 0 Answers
How do I specify the position of one object relative to another object? 2 Answers
Position in relation to another object 1 Answer
Aligning sprite with Canvas 0 Answers