Game Objects with multiple children taking time to SetActive initially

Hi guys , Basically i have a game object “Dictionary”
which has multiple prefabs (Roughly 500) which is instantiated during runtime and is disabled initially
while enabling it with a button click it takes a lot of time and unity freezes during this process
iam using SetActive(true) anitially
and on button click SetActive(False)

any idea on y this is happening???



I am not sure if I understand the problem because your very long sentence is not totaly clear to me. What I understand is that you want to instanciate 500 prefabs at runtime and the freeze happens at this moment. My answer corresponds to this interpretation :

The freeze sounds normal as you have 500 objects to handle inside the unique frame when you click the button. The problem is that the loop on the 500 objects is synchronous, it’s a group of instructions that execute during the frame when the button is clicked.

A thing you could do is writing a coroutine that splits the process on several frames. And while it’s not over, you can continue your game or display a loader depending on the behaviour you want.

In this way, there will be no “freeze” to give a negative effect.

Regardless of how the objects are parented you’re still enabling/disabling 500 objects at a time. That will take a while, especially if the child objects contain scripts which use OnEnable/OnDisable.

Is there a way to break down your structure into more manageable groups so that you don’t need to disable/enable as much at once?