Spawned Objects Not Packaging on Build - FINE in PIE

So another UE problem :face_exhaling:

My project is nearly finished, Ive been reqularly building to check, but now it seems I hit yet another problem. After examining my log files, Ive noticed that some spawned Actors are built VERY early on in the building process a long time before some of their dependent classes are built. But In the EDITOR, THE PIE and Standalone Game test everything is building in the order I expect.

WHY??? I’ve gone to great lengths to ensure things are built and created in order, and now UE just says ■■■■ it to that and does what it wants.

How to fix, is it possible to delay, prioritize, configure how UE builds and cooks these Actors

Have you tried adding the missing classes by
Project Settings =>Project => Packing => Additional Asset Directories to Cook => “fill in you directory with missing classes”

  • Are you cooking your content?
  • Are you using “Enable cooking on the fly”? (I’d turn it off)

So it turns out after a good read of the Actor Lifecycle and other documents, that I cannot use my custom class in the constructor of the spawned object, because although I do not construct them until runtime, it seems that upon packaging, cooking and building, UE preconstructs spawned actors as templates to be duplicated before it even creates basic things like the GameInstance, which is where my custom classes were built. Who would have thought?

So I moved my custom classes out of the spawned actor constructor, and into PostInitializeComponents, and now my game will build fine.

Thanks