UObject outer and GC

I’m trying to understand what an UObject’s ‘outer’ really means, and how it affects GC. From my understanding, the only GC guarantee seems to be:

  • If you store UObject A pointer as a member of UObject B, and mark it as a UPROPERTY, that UObject A will stay alive as long as UObject B is alive

What I’m trying to understand is what effect the UObject’s ‘outer’ actually has regarding GC. I was having some issues where:

  • UObject A gets created using NewObject(this) in some function inside UObject B, and used as a local scope varible (not a member)
  • When the game finishes, the GC runs and ensures everything is cleaned up
  • It goes through all UObjects and runs some code that, in between other things, tries to find each UObject’s outermost UObject
  • There’s a crash → UObject A has it’s outer set to an invalid (already deleted) UObject

So it seems that even though we set B as the outer of A, there isn’t a guarantee that A will be deleted before B, and the cleanup check will fail as it can’t find A’s outer. So what does ‘outer’ actually do?

What we were trying to accomplish was the creation of local scope UObjects. We seem to have fixed it by not specifying the outer, and letting it default to GetTransientPackage() - however, without fully understanding what TransientPackage is, I don’t feel like this is a proper fix and might just be working by luck in the GC run order.

Any clarification or help would be appreciated :slight_smile:

1 Like