Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Send message cannot be called during Awake, CheckConsistency, or OnValidate error message

Discussion in 'Scripting' started by Ferdowsur, Aug 29, 2019.

  1. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    115
    "Send message cannot be called during Awake, CheckConsistency, or OnValidate"

    I keep getting this warning message. It doesn't cause any problem but is filling up the log. Is there any way to disable this warning?



    It only happens when I do stuff during OnValidate() calls. On these lines on different sripts.

    Code (CSharp):
    1. GameObject prefab = Instantiate(characters[i].prefab);
    Code (CSharp):
    1. obj.transform.SetParent(transform);
    Code (CSharp):
    1. obj = new GameObject();


    Using Unity version: 2018.3.12f1


    Edit: I know I can disable some common warnings using stuff like this.
    #pragma warning disable 0168
    . But I don't know how to look for warning number for the error I am getting
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,136
    Well this is a runtime warning, not a compiler warning, so this doesn't apply. If it applied then the number you need would be a part of the message.

    I don't know why you're getting a warning like that on that code, though. That's strange.
     
    Ferdowsur likes this.
  3. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    115
    Yea, most of the search result for this error seems like from a ui slider. I added slider to test it and not getting any error from that. I haven't tested using different unity versions.

    Seems like I can avoid the warning by using delay call
    EditorApplication.delayCall += () => MyMethod();
    as a temporary fix.
     
  4. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    115
    If I use delayCall, it seems like the delayed call gets called twice when play mode starts. Avoided problem from that using a simple if else statement. But now I get random null reference exception due to delayCall. My uneducated guess is it's due to the instance of the script that calls for the delay call during editor mode not existing in play mode.

    I will check if it happens with different unity version and a fresh project.

    Edit: Yes. the error repeats
    Edit:fixed phrasing
     
    Last edited: Aug 29, 2019
  5. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    115
    Warning is reproduced from this code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NewBehaviourScript : MonoBehaviour
    6. {
    7.     void OnValidate()
    8.     {
    9.         GameObject obj = new GameObject();
    10.     }
    11. }
     
  6. Blinkq

    Blinkq

    Joined:
    Apr 19, 2015
    Posts:
    21
    yeap, have same error. This warning enoying, would appriciate, if someone will help with removing it
     
  7. ThatMunk

    ThatMunk

    Joined:
    May 17, 2017
    Posts:
    12
    +1 for a solution to this
    Running;
    Code (CSharp):
    1. Instantiate(Prefab, transform);
    on validate and getting this error in 2019.3.10f1.
     
  8. L42yB

    L42yB

    Joined:
    Dec 20, 2012
    Posts:
    25
    Bumping for a response. I have a ton of these warnings whenever I start the editor. I've seen no actual consequence for it, and I have no idea why they are happening.
     
  9. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    115
    I fixed the warnings for my own code with the temporary fixes stated above. But,
    HDRP lighting system keeps spamming the warning at random times at random intervals.

    Unity version: 2019.4.1f1.

    Had the issue with previous versions for a LONG time.
    To be fair, I am not sure if I did something to cause this issue. I messed with HDRP settings a lot & didn't try reproducing it with a fresh new project.

    Exact message:
    Code (CSharp):
    1. SendMessage cannot be called during Awake, CheckConsistency, or OnValidate
    2. UnityEngine.Rendering.HighDefinition.HDAdditionalLightData:OnValidate()
    Got exactly 851 times this message after 5min of opening the project. All the messages came within 1min, then stopped. I just want to say, thank god Collapse similar log toggle exists. :D
     
    Last edited: Jul 30, 2020
  10. L42yB

    L42yB

    Joined:
    Dec 20, 2012
    Posts:
    25
    This is the full stack trace I get for mine in the log. Seems to be related to generating a preview for assets. I get hundreds of them too. I still don't know why or what is causing them...


    SendMessage cannot be called during Awake, CheckConsistency, or OnValidate
    UnityEditor.EditorUtility:Internal_InstantiateRemoveAllNonAnimationComponentsSingle_Injected(Object, Vector3&, Quaternion&)
    UnityEditor.EditorUtility:Internal_InstantiateRemoveAllNonAnimationComponentsSingle(Object, Vector3, Quaternion)
    UnityEditor.EditorUtility:InstantiateRemoveAllNonAnimationComponents(Object, Vector3, Quaternion)
    UnityEditor.EditorUtility:InstantiateForAnimatorPreview(Object)
    UnityEditor.PreviewData:UpdateGameObject(Object)
    UnityEditor.PreviewData:.ctor(Object)
    UnityEditor.GameObjectInspector:GetPreviewData()
    UnityEditor.GameObjectInspector:RenderStaticPreview(String, Object[], Int32, Int32)
    UnityEditor.AssetPreviewUpdater:CreatePreviewForAsset(Object, Object[], String)
     
  11. L42yB

    L42yB

    Joined:
    Dec 20, 2012
    Posts:
    25
    I also have this stack trace, which really looks like it is entirely a Unity issue:

    SendMessage cannot be called during Awake, CheckConsistency, or OnValidate
    UnityEditorInternal.InternalEditorUtility:LoadSerializedFileAndForget(String)
    UnityEditor.WindowLayout:LoadDefaultWindowPreferences()
     
  12. gcast1995

    gcast1995

    Joined:
    Oct 27, 2019
    Posts:
    25
    Bump, also having a similar issue.
     
  13. vsugrob

    vsugrob

    Joined:
    Mar 9, 2014
    Posts:
    4
    Bump. In my case it's reproduced by calling
    gameObject.AddComponent <AnyComponentType> ();
    from
    OnValidate()
    .
    Console output becomes unreadable.
     
unityunity