procedural object doesn’t work in Scene due to OnValidate()

I was following some tutorial on procedural generation and ran into this issue where I’m getting errors and when they are not. I’ve slimmed the code down for the following example but…

private void OnValidate() {     test(); }  void test() {     GameObject meshObj = new GameObject("empty"); } 

SendMessage cannot be called during Awake, CheckConsistency, or OnValidate UnityEngine.GameObject:.ctor(String)

why is this happening for me?