FObjectFinder doesn't find in 4.21?

Hello,

Using this code in constructor:

const ConstructorHelpers::FObjectFinder<UTexture2D> TransparentTextureObject(TEXT("Texture2D'/Game/Yag/UI/Icons/TransparentSquare-128.TransparentSquare-128'"));
TransparentTexture = TransparentTextureObject.Object;

With this call in a method:

UTexture2D* TextureToDisplay = TransparentTexture;

used to work in 4.20.

Now in 4.21 i get a crash wirh nullptr access violation.

Anything changed in 4.21 or could this be a bug ?

Thanks

Cedric

The problem seems to be more general.

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.

All that used to work well in 4.20.

Am i missing something with 4.21 ?

Thanks

Cedric

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 ?

Cedric

Ok, problem worked around.

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
    [...]
    
}

It’s not pretty but it did the job.

If anyone has a better suggestion, i’m all ears.

Cedric