【问题标题】:Unity 3D: What method is being used in this SendMessage?Unity 3D:此 SendMessage 中使用了什么方法?
【发布时间】:2020-09-27 18:22:49
【问题描述】:

当我在编辑器中时,我有一个脚本当前正在运行 OnValidate() 来更新游戏对象。有时,当事情重置时,脚本会运行以下几行:

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

作为回报,我最终会在控制台中收到一些警告,如下所示:

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)

所以我的问题是:程序尝试使用无法调用的 SendMessage 发送什么消息/方法?

【问题讨论】:

    标签: c# .net visual-studio unity3d


    【解决方案1】:

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

    显然 set_parent 在幕后使用了 SendMessage,这可能会在 OnValidate 调用中出现问题。

    【讨论】:

    • 是的,我也找到了那个。我想我正在寻找一个更好的解释。我很想知道它到底会导致什么出错,所以我至少可以留意它。不过谢谢!
    猜你喜欢
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多