Hi everyone,
I’m trying to instance some blueprints from a C++ class. I got it working in two cases but my third case fails. I get an Exception 0x80000003 encountered at address inside of CreateWidget in the line return Cast(UUserWidget::CreateWidgetInstance(*OwningObject, UserWidgetClass, WidgetName));. Here’s an overview of my code.
// In UQuestRadioMatrixQuestion.h:
TArray<TObjectPtr<UQuestRadioMatrixRow>> rows;
// In UQuestRadioMatrixQuestion.cpp:
void UQuestRadioMatrixQuestion::NativeConstruct() {
// ...
rows[i] = NewObject<UQuestRadioMatrixRow>();
rows[i]->Setup();
// ...
// In UQuestRadioMatrixRow.cpp:
void UQuestRadioMatrixRow::Setup() {
// ...
TObjectPtr<UQuestCheckbox> checkBox(CreateWidget<UQuestCheckbox>(this, CheckboxBPClass)); // This is what calls CreateWidget<>() which then throws an exception. It's not this line that fails, it's the one in CreateWidget<>() I mentioned above.
// ...
}
// UQuestRadioMatrixRow.h:
UCLASS()
class UNREALQUESTBP56_API UQuestRadioMatrixRow : public UQuestRadioQuestion
{
GENERATED_BODY()
public:
virtual void Setup() override;
// ...
};
// UQuestRadioQuestion.h:
UCLASS()
class UNREALQUESTBP56_API UQuestRadioQuestion : public UQuestCheckboxQuestion {
GENERATED_BODY()
public:
// ...
};
// UQuestCheckboxQuestion.h:
UCLASS()
class UNREALQUESTBP56_API UQuestCheckboxQuestion : public UQuestQuestion {
GENERATED_BODY()
protected:
virtual void NativePreConstruct() override;
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSubclassOf<UQuestCheckbox> CheckboxBPClass;
TArray<TObjectPtr<UQuestCheckbox>> AnswerBoxes;
UFUNCTION(BlueprintCallable)
virtual void Setup();
};
// UQuestQuestion ultimately inherits from UUserWidget
I obviously left out all the members that are not involved in the problematic function call.
Now you can see that there is another version of Setup() in UQuestCheckboxQuestion. It looks like this:
void UQuestCheckboxQuestion::Setup() {
TObjectPtr<UQuestCheckbox> checkBox(CreateWidget<UQuestCheckbox>(this, CheckboxBPClass));
// ...
}
}
You can see the line is identical to the one in the other Setup function. All the parts that differ are unrelated to the call to CreateWidget<>(). I used the debugger and checked and the only difference in the call is the content of this. I also made sure that CheckboxBPClass is set in all cases. It is.
Now I can call Setup() on instances of both UQuestCheckboxQuestion and UQuestRadioQuestion and they will create widgets just fine, but on UQuestRadioMatrixRow it doesn’t work and I am puzzled by this, since UQuestRadioMatrixRow inherits from the other ones.
There is one other thing that’s different that I can think of. As you can see, instances of UQuestRadioMatrixRow are created with NewObject(). Instances of the other two classes however are created from blueprints (Create Widget node), since there are blueprint classes that inherit from UQuestCheckboxQuestion and UQuestRadioQuestion. I can’t see how that would explain my problem though.
Please help me fix this issue and understand what’s going on.