- Home /
RectTransform.TransformPoint returning zero everytime after Unity 4.6.3
RectTransform.TransformPoint and RectTransform.GetWorldCorners return zero after Unity 4.6.3 update, not in 4.6.2. It continues to fail in Unity 5 and 5.1.
Vector3[] corners = new Vector3[4];
rectTransform.GetWorldCorners(corners);
Doing this:
Vector2 bottomLeft = rectTransform.TransformPoint(rectTransform.rect.min);
Vector2 topRight = rectTransform.TransformPoint(rectTransform.rect.max);
is the same. A zero result. Do anyone has this problem? What to do? Thanks.
I just tested with the simplest scene and script I could make, on Unity 5.0.2f1 Personal and this is not returning zero.
The scene is just a $$anonymous$$ain Camera and a Canvas with a Panel inside. The panel is stratched and has this script attached:
using UnityEngine;
using System.Collections;
public class WorldCornersTest : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start () {
RectTransform rectTransform = GetComponent<RectTransform> ();
Vector3[] corners = new Vector3[4];
rectTransform.GetWorldCorners(corners);
for (int i = 0; i < corners.Length; i++)
Debug.Log (corners [i]);
Vector2 bottomLeft = rectTransform.TransformPoint(rectTransform.rect.$$anonymous$$);
Debug.Log (bottomLeft);
Vector2 topRight = rectTransform.TransformPoint(rectTransform.rect.max);
Debug.Log (topRight);
}
}
When I press play I get this output: (0.0, 0.0, 0.0) (0.0, 574.0, 0.0) (861.0, 574.0, 0.0) (861.0, 0.0, 0.0) (0.0, 0.0) (861.0, 574.0)
So, your problem must be somewhere else, can you share some more code? How are you getting that rectTransform reference? $$anonymous$$aybe you're using a reference to a prefab ins$$anonymous$$d of an instance of a prefab somehow, prefabs that has not been instantiated don't throw an error but make wierd things.
I discovered that I need to ask in Update until rectTransform.with is different from zero until I get proper values. So at some point the engine is ready for RectTransform.TransformPoint to work properly....