set staticmesh from referenced blueprint variable in class constructor

Im currently removing hard coded paths from c++ code and try set them in blueprints.
In my custom actor i have editable UStaticMesh or UParticle pointer variables, that can be referenced in the blueprint.

UStaticMesh *m_pStaticMesh = nullptr;

For some reason this variables are always NULL, when i try to call


It works when i set them in BeginPlay() function.

Hi there!

BP variables that you set in the Editor do not become valid until PostInitComponents!

So you can’t set them in the C++ class constructor.

For this reason I typically use Begin Play, as I usually need to override that anyways.

So the lesson:

Never try to apply BP-set variables in the C++ constructor, they wont be valid yet :slight_smile:



Thank you, that make sense! :slight_smile: