Activating gameobject takes up to 120 secs

Hi,

I am currently having a few troubles with loading scenes which is quite strange:

My project consists of a parent scene that loads scene A. After leaving scene A (resources are freed etc.) scene B is loaded by the parent scene. It consists nearly of the same gameobjects that scene A used but loading takes several minutes.

Looking further into the detail, the time is obviously used when deactivating a gameobject (let’s call it X) at the start of the scene which has approx 150 child objects attached, each with further childs and (box) colliders, maybe 1500 of them. This is done by gameObject.SetActive(false) which is the only line that takes up to 120 seconds. Deactivating slightly smaller gamobjects (maybe 50 childs) works in 0.0x seconds. Also loading same objects in scene A takes only 0.0x seconds.

A few times I stopped at a break point in the debugger for a minute, afterwards the loading went very fast. Does anyone have experience with slow loading of scenes like described above?

Any help appreciated!

I assume you mean a total of 1500 objects, not 1500 per child, right?
Either way, these seem like very high numbers. I cant really think of a reason for why this would be necessary, so if you could explain why you need them, this may get you an even better answer to your problem.

As for the actual loading times, disabling 1500 child objects by setting the parent to disabled should definitely not take anywhere close to 120 seconds. Maybe for this gameobject in particular one or many of its children have heavy operations in their OnDisable methods?

Yeah correct, approx 1500 objects attached to the parent object. It is representing a military hierarchy: one army has several corps objects below, which have several divisions and each division several brigades & regiments.

The hierarchy looks as following (showing only a part):
5009963--490004--upload_2019-9-28_16-47-56.png

Nearly each object has a box collider attached. Activating the object seems not expensive , while deactivating takes incredibly long (time in secs):

When i deactivated the colliders of all “blockpivot” objects (approx 1300 of the 1500), the deactivation was smooth:

Note: there are no OnDisable actions. It seems to be a collider issue only. I have even tried to increase fixedupdate (physics) to 10 seconds to rule out any intermediate updates within the deactivation process.

So it must have something to do with the box collider and physics:
5009963--490013--upload_2019-9-28_17-7-44.png
(I even tried to rule out operations within OnTriggerEnter and OnTriggerExit of those objects).

Deactivating “Is Trigger” for these box colliders result in much faster loading:

Hm, i really dont know why it takes so long to disable the colliders, so somebody else can hopefully answer that.

Either way i can imagine having thousands of colliders / triggers is not very efficient anyways. Are you seing a performance hit in game? While this is not what you asked for, you may wanna have a look at DOTS, which can easily handle tens of thousands of units, including interactions and so on, very efficiently.

Thanks anyway Yoreki!
I used a workaround now where I deactivate the collider trigger in the prefabs that create the unit hierarchy, after loading I am reactivating it by code. Improves the loading speed by factor 7x!