Problem:
If I create an object and set a property using the reflection system the object becomes invalid - it fails an assert in ConditionalDestroy() - it is caused because when the BeginDestroy() function is called on the object somehow the PostLoadSubobjects() is called instead, and BeginDestory() isn’t called at all.
Code I used:
UCLASS(BlueprintType, EditInlineNew)
class TPSTEST_API UTestObjectBase : public UObject
{
GENERATED_BODY()
protected:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Params)
bool bTestParam = true;
};
In character Header:
UPROPERTY()
class UTestObjectBase* ObjectPtr;
Character BeginPlay:
//////////////////////////////////////////////////////////////////////////
void ATPSTestCharacter::BeginPlay()
{
ObjectPtr = NewObject<UTestObjectBase>(this, UTestObjectBase::StaticClass());
UBoolProperty* Property = Cast<UBoolProperty>(ObjectPtr->GetClass()->FindPropertyByName("bTestParam"));
if (Property != nullptr)
Property->SetPropertyValue(reinterpret_cast<void*>(ObjectPtr), false);
}
Easiest way to reproduce:
- Create a C++ tps template project (4.15)
- Paste the attached files (overwriting the default character .h/.cpp).
- Start the game in editor
- Press esc to stop it
Interesting part is the fact that the error looks totally random, but I had exactly the same results in a much more complicated environment.
Did I miss something?