I commented the code in my post and then got another nullptr access violation in this code:
// update display in help widget
UYagHelpWidget* HelpWidget = Cast<UYagHelpWidget>(ThisPawn->HeadsetUIComponent->GetUserWidgetObject()->WidgetTree->FindWidget(FName(TEXT("BP_TabHelp"))));
It tells me that GetUserWidgetObject() returned a null pointer.
I’m starting to think that UUserWidget are created later in 4.21 than 4.20: the hereabove code is in a UUserWidget and it doesn’t crash when i add this line at the beginning of the method:
if (!this) return;
Similarly, GetUserWidgetObject() returning a nullptr would be the same problem of undefined widget.
Did something change in 4.21 with the timing of widget creation ?
It seems that in 4.21 the Default Pawn class is assigned to the player contoller later that in 4.20.
So the default pawn doesn’t exist when PC’s BeginPlay() is called.
So i used the following workaround:
void AYagPlayerController::BeginPlay()
{
Super::BeginPlay();
GetWorld()->GetTimerManager().SetTimer(InitializePCHandle, FTimerDelegate::CreateUObject(this, &AYagPlayerController::InitializePC), .1f, true);
}
void AYagPlayerController::InitializePC()
{
if (!ThisPawn) return;
// clean init timer
GetWorld()->GetTimerManager().ClearTimer(InitializePCHandle);
// the rest of this function is just a copy paste of what was in BeginPlay() previous to 4.21
[...]
}