So I have been working on an in editor script when I came across the following problem. My code:
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class anchorTool : MonoBehaviour {
void Update () {
#if UNITY_EDITOR
ownRectTransform = gameObject.GetComponent<RectTransform>();
Debug.Log(ownRectTransform.rect.width);
Debug.Log(ownRectTransform.rect.height);
#endif
}
}
I have found Update is called in the editor once when the scene is loaded. During that first call the values returned for width and height are incorrect. In all subsequent call the values ARE correct. Is there a reason for this and is there any way to get the correct values in that first call?
I already found out that you can’t start co-routines in edit mode, so I am feeling lost.