So i been working on a inventory system and it was coming along great.
Drag and Drop is working and life was looking up.
Then i discoverd that my delegates is making my editor / game crash.
So am wondering where is it best to bind delegates located in the player controller?
Here is my class for it.
And here is the implementation.
This all works great until i have opend and closed my inventory widget, next time i open it again it crashes.
Removing the lines in void UInventoryUserWidget::Construct_Implementation() "solves" the crash but am then left with no delegates.
The reson for not doing this is the constructor is that am assuming that there is no Player Controller at the time of the constructor is called?
Thanks for any help.
WCode
Drag and Drop is working and life was looking up.
Then i discoverd that my delegates is making my editor / game crash.
So am wondering where is it best to bind delegates located in the player controller?
Here is my class for it.
Code:
class MY_API UInventoryUserWidget : public UUserWidget { GENERATED_UCLASS_BODY() public: /* UUserWidget:: Overriden methods. **/ // Overriden to binds delegates on the AMyPlayerController:: at runtime (to avoid PC not present.) virtual void Construct_Implementation() override; /* UInventoryUserWidget :: Class methods. **/ UFUNCTION() void CallPlayerPickupItem(FItemInventoryStruct NewItemToInventory); // Called when the delegate AMyPlayerController::OnPlayerStopLookingAtItemPickup is executed. UFUNCTION(BlueprintImplementableEvent, meta = (FriendlyName = "Notifie Player Picksup Item")) virtual void OnPlayerPickedItem(FItemInventoryStruct ItemThatWasPickedUp); };
Code:
UInventoryUserWidget::UInventoryUserWidget(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) { } void UInventoryUserWidget::Construct_Implementation() { Super::Construct_Implementation(); AMyPlayerController* PC = CAST_TO_MY_PC(GetOwningPlayer()); if (PC) { // Calls CallPlayerPickupItem() that in turn calls the "BlueprintImplementableEvent" on OnPlayerPickedItem() PC->OnPlayerPickupItem.AddDynamic(this, &UInventoryUserWidget::CallPlayerPickupItem); } } void UInventoryUserWidget::CallPlayerPickupItem(FItemInventoryStruct NewItemToInventory) { OnPlayerPickedItem(NewItemToInventory); }
Removing the lines in void UInventoryUserWidget::Construct_Implementation() "solves" the crash but am then left with no delegates.
The reson for not doing this is the constructor is that am assuming that there is no Player Controller at the time of the constructor is called?
Thanks for any help.
WCode
Comment