Thursday, February 29, 2024
HomeGame DevelopmentUnity replace sizeDelta in OnValidate primarily based on Structure Group computed values

Unity replace sizeDelta in OnValidate primarily based on Structure Group computed values


I am making an attempt to replace the sizeDelta of a RectTransform in OnValidate. I am making an attempt to seize the computed values from a Structure Group.

This is what I’ve received:

#if UNITY_EDITOR
        void OnValidate()
        {
            UnityEditor.EditorApplication.delayCall += Resize;
        }

        non-public void Resize()
        {
            if (this == null) return;
            RectTransform parentRect = (RectTransform)gameObject.rework;
            RectTransform textRect = (RectTransform)tabText.rework;
            textRect.sizeDelta = new Vector2(parentRect.rect.top, parentRect.rect.width);
            layoutElement.preferredHeight = parentRect.rect.top;
        }
#endif

At first this appeared to be working, but it surely solely works the primary time OnValidate runs. Subsequence invocations of Resize() units the sizeDelta to Vector2(0, 0).

I am questioning what causes this and if there is a solution to keep away from it. If I take away the delayCall, the values are appropriate, however I get warnings:

SendMessage can’t be known as throughout Awake, CheckConsistency, or
OnValidate

I might like to do that at edit time since there isn’t any must compute these things at runtime.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments

Arnavsijapati on Planet of Lana – Beta Demo
Jai Kishor Upadhyay on Planet of Lana – Beta Demo