It happen in Unity3D Editor mode.
When I want to auto create a folder like structure, and error show in console.
void Reset() { GameObject go = new GameObject("Sub-Folder"); go.transform.SetParent(transform); // Null reference "go == null" }
the code above will fail. due to “go” value is null.
so the solution is simple.
DON’T process “new GameObject(blah)” within Editor session.
I prefer using “Invoke” hack in this case.
void Reset() { Invoke(nameof(Editor_Init), 0); // try not to use "string" type here,
// instead we can use nameof() to label which function call we using.
// process in next ZERO second is a hack, to run the same thing without error. } void Editor_Init() { GameObject go = new GameObject("Sub-Folder"); go.transform.SetParent(transform); // will work like this. ya~~~ }