Unity 2022 Warning with Canvas Scaler: SendMessage cannot be called during Awake

I updated to Unity 2022 and get now ~500 of these warnings:

SendMessage cannot be called during Awake, CheckConsistency, or OnValidate (MyCanvas: OnRectTransformDimensionsChange)
UnityEngine.UI.InputField:OnValidate ()

I get them on canvas objects, images, buttons.

If I disable the Canvas Scaler component on the canvas gameobject, the warnings are gone. Is this a bug or something I’m doing wrong?

1 Like

Update: I realize that this now happens only the first time I enter playmode. Afterwards the warnings are gone. Wasn’t the case yesterday… so weird thing to happen.

edit: the above today is not true anymore. Now they show every time I enter playmode and they now as well show literally for every single UI element I have in the hierarchy. No exception. 999+ warnings when I start to play my game.

Seems clear that this is a Unity bug but I’m not sure what causes it. Seems I’m the only one with this problem?

Nope, not just you. I too just upgraded from 2021 LTS to 2022 LTS and I’m getting these errors as well even though my project uses SendMessage nowhere.

yeah I reverted back to Unity 2021 (have some other issues with unity 2022 too). But can’t work with 999+ warnings in the console. Literally every UI element I have in my hierarchy is triggering this warning. Hilarious.

This is still happening in 2023.3.20. This is a bug in Unity’s InputField.OnValidate. If you look at that function:

    #if UNITY_EDITOR
        // Remember: This is NOT related to text validation!
        // This is Unity's own OnValidate method which is invoked when changing values in the Inspector.
        protected override void OnValidate()
        {
            base.OnValidate();
            EnforceContentType();
            EnforceTextHOverflow();

            m_CharacterLimit = Math.Max(0, m_CharacterLimit);

            //This can be invoked before OnEnabled is called. So we shouldn't be accessing other objects, before OnEnable is called.
            if (!IsActive())
                return;

            // fix case 1040277
            ClampPos(ref m_CaretPosition);
            ClampPos(ref m_CaretSelectPosition);


            UpdateLabel();
            if (m_AllowInput)
                SetCaretActive();
        }

    #endif // if UNITY_EDITOR

You can see that they are aware they aren’t supposed to be sending messages, but then do it anyway. I fixed this by just not doing that:

using UnityEngine.UI;

public class UnvalidatedInputField : InputField {
    protected override void OnValidate() {}
}

Your mileage may vary. Presumably there’s some downside to having this component refuse to validate, but it seems to work.