资源大湿 发表于 2020-4-9 13:44

当inspector发生改变时OnValidate,调用destory报错

Destroying GameObjects immediately is not permitted during physics trigger/contact, animation event callbacks or OnValidate. You must use Destroy instead.

报错,如何删除子节点在这个方法中》?

资源大湿 发表于 2020-4-9 13:45


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

      // Main();
    }

加入延迟执行,并且销毁方法改为
while (gameObject.transform.childCount > 0)
      {
            DestroyImmediate(gameObject.transform.GetChild(0).gameObject);
      }
页: [1]
查看完整版本: 当inspector发生改变时OnValidate,调用destory报错