Jee
Jee

Reputation: 977

Unity 3D: What method is being used in this SendMessage?

I have a script currently running OnValidate() to update a GameObject while I'm in the editor. At times, when things reset, the script will run the following lines:

private void OnValidate()
{
    if (reset == true)
    {
        obj.transform.parent = transform;
    }
}

In return, I end up with some Warnings in the console like the following:

SendMessage cannot be called during Awake, CheckConsistency, or OnValidate
UnityEngine.Transform:set_parent(Transform)
Planet:Initialize() (at Assets/Planet.cs:46)
Planet:OnValidate() (at Assets/Planet.cs:20)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

So my question is: What message/method is the program trying to send using SendMessage that it is unable to call?

Upvotes: 1

Views: 1409

Answers (1)

AndreasHassing
AndreasHassing

Reputation: 691

See https://forum.unity.com/threads/sendmessage-cannot-be-called-during-awake-checkconsistency-or-onvalidate.428580/#post-2772943

Apparently set_parent uses SendMessage behind the covers, and that can be problematic from OnValidate calls.

Upvotes: 1

Related Questions