I try to invoke a BlueprintNativeEvent in my object’s PostInitProperties(), but a strange behaviour occurs.
Test.cpp:
void Atest::PostInitProperties()
{
Super::PostInitProperties();
if(initAsStatic()){
//this should trigger
mesh = NewObject(this,UStaticMeshComponent::StaticClass());
}else{
//but this triggers instead
mesh = NewObject(this,USkeletalMeshComponent::StaticClass());
}
}
//declared as UFUNCTION(BlueprintNativeEvent, BlueprintCallable) in Test.h
bool Atest::initAsStatic_Implementation()
{
D(“initAsStatic in c++”) //my macro to printString in editor.
return true;
}
void Atest::PostInitProperties()
{
Super::PostInitProperties();
if(initAsStatic()){
//this should trigger
mesh = NewObject(this,UStaticMeshComponent::StaticClass());
}else{
//but this triggers instead
mesh = NewObject(this,USkeletalMeshComponent::StaticClass());
}
}
//declared as UFUNCTION(BlueprintNativeEvent, BlueprintCallable) in Test.h
bool Atest::initAsStatic_Implementation()
{
D(“initAsStatic in c++”) //my macro to printString in editor.
return true;
}
The above C++ class has a BP child, with this override:
As you may have noticed, no matter the default C++ _Implementation or the override, both return true and print some string to indicate they run, but on practice no string is printed and false is returned from initAsStatic() at line4.
i assume that false is returned because it is the default return value of empty bool functions.
The function works well if triggered from BeginPlay or during regular runtime though. why is it not working in PostInitProperties()?