SetActive and Garbage collection

Hi

I cant seem to find an answer so I have a game object (prefab cube object) and when i use SetActive to false during runtime i get 72.5KB of garbage showing in the profiler when testing on a Samsung J3 device (android) via a USB WIFI connection.

So my setup is simple, i have a parent object and 4 children. Each has a OnTriggerEnter and then when the user presses (keyboard A) the child objects get deactivated.

Any ideas why? i even tried removing the child scripts but this still created garbage. So i have know idea why disabling a game object does create garbage.

Overview of inspector setup
Empty game object (Script with OnTriggerEnter & Disable Children script)

  • Cube Object (with mesh)
  • Box Collider Trigger (Script with OnTriggerEnter)
  • Cube Object
  • Box Collider Trigger (Script with OnTriggerEnter)
  • Cube Object
  • Box Collider Trigger (Script with OnTriggerEnter)
  • Cube Object
  • Box Collider Trigger (Script with OnTriggerEnter)

Do you have OnDisable code in any components attached to the deactivated objects? Does said code create garbage?

Are you 100% certain that it’s the SetActive causing it, and not other code in your OnTriggerEnter call?

You show no code, but only a screenshot of the profiler, it’s not a whole lot to go on.

Hi, sorry i posted this and forgot to attach it, ill add it to my post when i get home. I basically have just a OnTriggerEnter on each child object and that’s it. It does nothing at the moment when a collider hits. Thats why i was asking about the SetActive and garbage. But the screenshot just shows the OnTriggerEnter being disabled at the exact frame its actioned.

Nick