So been trying all day to figuer out way my Editor crashes when pressing Stop/ Esc in PiE.
And i managed to figure out that it is the delegates in my extended UUSerWidget::.
I have over-riden the method like this:
void UInventoryUserWidget::Construct_Implementation()
{
Super::Construct_Implementation();
AMyPlayerController* PC = Cast<AMyPlayerController>(GetOwningPlayer());
if ((PC) && PC->IsValidLowLevel())
{
if (PC->OnPlayerPickupItem.IsBound())
PC->OnPlayerPickupItem.RemoveDynamic(this, &UInventoryUserWidget::CallPlayerPickupItem);
if (PC->OnPlayerInventoryUpdated.IsBound())
PC->OnPlayerInventoryUpdated.RemoveDynamic(this, &UInventoryUserWidget::CallInventoryUpdated);
// Calls CallPlayerPickupItem() that in turn calls the "BlueprintImplementableEvent" on OnPlayerPickedItem()
if (!PC->OnPlayerPickupItem.IsBound())
PC->OnPlayerPickupItem.AddDynamic(this, &UInventoryUserWidget::CallPlayerPickupItem);
// Calls CallInventoryUpdated() that in turn calls the "BlueprintImplementableEvent" on OnInventoryUpdated()
if (!PC->OnPlayerInventoryUpdated.IsBound())
PC->OnPlayerInventoryUpdated.AddDynamic(this, &UInventoryUserWidget::CallInventoryUpdated);
OnConstructedDone();
}
}
Is this wrong or what am i doing wrong ?
I asked a similar qustion on the forums a time back and this is the solution.
But running this outside the editor and it don`t crash.
"So been trying all day to figuer out way my Editor crashes when pressing Stop/ Esc in PiE. "
I dont think it’s your delegates, I think it’s the use of Player Controller in a constructor!
In PIE, the PC becomes null around the time of exiting the PIE instance, and I have had crashes related to this with Solus
The solution is to make absolutely sure your are not calling the PC when it could be null, and preferrably not in a constructor that is apparently getting run on PIE exit!
#Crash Pattern
The crash pattern you describe matches my experience with Playercontroller and exiting PIE, not anything to do with widgets or delegates.
AMyPlayerController* PC = Cast<AMyPlayerController>(GetOwningPlayer());
with this
TObjectIterator<AMyPlayerController> Itr;
if(!Itr) return; //<~~~~ this is what happens on PIE exit
AMyPlayerController* PC = *Itr; //Safe to dereference now
This is the code I use in Solus to work around this issue !
PS: ultimately It would be best if you didnt need to access your PC in a constructor.
Thanks for the tip it did not solve the problem am afraid.
The crash happens as long as am exeting PiE, but only if the delegae in the UserWidget has been called.
Removing the delegates “solves” the issue.
So am thinking i maybe did a stupid mistake.
Also is it preferd to only work with smart pointers/ refrences when dealing with UMG?
PS: ultimately It would be best if you didnt need to access your PC in a constructor.
Do you know of a diferent method that could work for delegate binding?