Why some inspector's open time take so long?

I have some script object that has 15~20 scripts as components.

There was no problem, but today suddenly it takes so long time to show and load the object’s inspector things.

Almost I can’t control and set its inspector things. Other gameobjects has no problem.

Why this happen and how to fix?

Desperate…

You can profile the editor.

Open the profiler, turn on deep profiling and profile editor, and then click the object who’s inspector is slow. That’ll probably show you the culprit.

Thx, but if find it, how to deal it? I can’t delete because it has so many drag&drop assingment to inspector. If I delete it, its all gone.

→ So I solved. Problem was one script file. I removed all the changes I made (remove some variables), and it is solved. I don’t know why this occur problem though.

So I found more precisely.

class Character{
public Skill skills;
}
class Skill{

}

Originally code like above, if I add Character type variable in Skill class,

class Skill{
public Character Target;
}

Then inspector become so slow. This is because maybe variable type reference’s infinite circulation. (In this case, Character->Skill->Character->Skill…)

Yeah, it should also be spamming a million complaints a you a second that there’s too deep recursion in your Character class. That’s going to be the cause of most of the slowdown.

Wait, there should be no problem with two classes holding references to each other like that, right? Something else must be going on in there…

Actually, Character class has List variable. Maybe because of this? I don’t know well, but the inspector slowdown reason is clearly Character variable inside Skill class.

It is if the classes are both serialized, and both not inheriting from UnityEngine.Object.

If they were engine Objects, Untiy would store a reference to the object (or null) on serialization, and you’d be fine. But since they’re not, Unity tries to store their data. Their data includes the data in the other object, and so on.

This is not so strange, and can happen outside of Unity. If you try to do this, it won’t compile:

    public struct A
    {
        public int a_int;
        public B b;
    }
   
    public struct B
    {
        public int b_int;
        public A a;
    }

Since structs are created and passed by value, so both of those contain infinite bytes.