Um, never mind, I asked ChatGPT:
" In Unreal Engine, the constructors of classes, including actor classes, are automatically invoked during the engine’s initialization process. This behavior occurs even if you don’t explicitly use the class in your game code. The Unreal Engine runtime system automatically initializes all classes during startup to ensure that they are ready for use if needed. This behavior is part of the engine’s reflection system and is common in many object-oriented game engines and frameworks.
The reason for this automatic initialization lies in Unreal Engine’s need for reflection, serialization, and various other engine features. Unreal Engine uses the information gathered during the construction of these classes for a variety of purposes, including:
- Reflection: Unreal Engine needs to know about the properties, functions, and other members of classes to support features like Blueprint exposure, serialization, and replication. This information is gathered during class construction.
- Garbage Collection: Unreal Engine’s garbage collector needs to understand the memory layout and references of all objects. Class construction provides essential information for proper garbage collection.
- Editor Support: In the Unreal Editor, classes and their properties need to be visible and accessible even if they are not explicitly used in game code. The editor relies on the constructed classes to provide a rich user experience.
Due to these requirements, Unreal Engine initializes all classes during startup, leading to the invocation of constructors. This means you can’t make assumptions about the construction order of classes, especially if you’re relying on side effects in constructors. It’s a good practice to minimize side effects in constructors and use other initialization methods like BeginPlay
for actors to ensure predictable behavior."