Initialization Documentation

Could we please get some documentation that covers the uses of the different initialization functions; for instance covering things like BeginPlay, PreInitializeComponents, PostInitializeComponents, PostInitProperties, OnConstruction. Then have that documentation cover use cases, for instance when do we want to use PreInitializeComponents versus PostInitializeComponents versus PostInitProperties, etc.

There really no “when do we want to use” but rether when you need to do use it as each function let you inject code in any stage of initiation, if you don’t have any code which need to be executed in premature state of actor then safest approach is to run it in a latest one (PostInitializeComponents or BeginPlay). If you want you can follow actor initiation stages starting from this line:

Only importent thing you need to know is this that all initiation functions are also called in editor when you placed thing on the level, thats why BeginPlay() was made wihich is executed right after PostInitializeComponents (just because it needs to be in sequence, but they practicly the same point) but only in gameplay initiation (not editor):

	if (bActorsInitialized)
		// Call InitializeComponent on components

		if (!bActorInitialized && !IsPendingKill())
			UE_LOG(LogActor, Fatal, TEXT("%s failed to route PostInitializeComponents.  Please call Super::PostInitializeComponents() in your <className>::PostInitializeComponents() function. "), *GetFullName() );

		if (()->HasBegunPlay() && !deferBeginPlayAndUpdateOverlaps)

PostInitProperties and OnConstruction is even ealier stages PostInitProperties is UObject function and if i’m not mistaken it’s when properties values are set to defaults and any other modification (like detail tab changes) are also applied so you are sure variables are accurately set up.

1 Like

Thank you very much , I appreciate the write up, I’ll look into what you’ve said.