I’m making a very simple 3D game that requires objects to activate and deactivate on collisions. But I’ve run into a problem where Unity hangs for 2-3 seconds when GameObject.SetActive(true) is called. Weirdly enough, I did some further testing and found out that Unity only hangs when true is called but not when false is called.
Activating objects causes problems but not deactivating…
Don’t know what to do at this point.
I believe it is established that simply activating t he objects is not a Problem in Unity. Too many people are doing it, and no-one has reported a similar issue. So I believe the culprit is with something that happens duringactivation of your object, probably something in a script you added.
First, the obvious: it should be gameObject.SetActive(true) (with a lowercase ‘G’ at the start)
Next, to get to the bottom of this, try the following with the object in question:
disable all components, and all child objects, then enable the object. Do you see the pause?
now successively enable the scripts (but not childs) and re-try. Do you see the pause?
Progress through all the cildren similarly until you find the culprit
It’s mind-numbingly dull work, but it should get you to the root cause.