OnConstruction not called on game start

anonymous_user_7a9aff17
Tue, 24 Feb 2015 00:00:40 +0000
C++

Our team has been working with 4.3 for a while now and we have just switched to 4.6, finally.

We have created a placeable pickup which changes its appearance based on some values inside the GameMode. GameMode doesn’t exist in the Editor - so we have been forced to display a generic pickup shape until the game or PIE session starts, then the GameMode becomes available again, pickups get recreated and set themselves up in OnConstruction.

This worked fine until we migrated to 4.6, now the game start does not invoke OnConstruction anymore, while class constructors still get called (from ULevel::Serialize). If the same pickup is spawned from blueprints, OnConstruction always executes. It’s funny because there is a ton of init functions in Actor.h (like PostActorCreated), yet OnConstruction does not work consistently. Just to illustrate, this is a rather small sample of available init functions from AActor:

PostLoad/PostActorCreated - Do any setup of the actor required for construction. PostLoad for serialized actors, PostActorCreated for spawned

OnConstruction - The construction of the actor, this is where Blueprint actors have their components created and blueprint variables are initialized

PreInitializeComponents - Called before InitializeComponent is called on the actor’s components

PostInitializeComponents - Called after the actor’s components have been initialized

BeginPlay - Called when the level is started

Which function should I override instead of OnConstruction to make use of GameMode?
What is the correct way of getting GameMode on game start and is it a safe practice in a single player game?

P.S. I have been using BeginPlay ever since without much trouble, but wanted to clarify if it will always work as I want it to.

4 posts - 1 participant