Hi,
I have an issue where my property is undefined inside a function. The property is bound using “meta(BindWidget)”.
In my headerfile:
UCLASS()
class MYPROJECT_API UInventoryPanelWidget : public UUserWidget
{
GENERATED_BODY()
public:
// ==========================================================================
// PROPERTIES & VARIABLES
// ==========================================================================
UPROPERTY(meta=(BindWidget))
UWrapBox* Items;
In my CPP file:. The isse is here, CapacityInfo & Items is always undefined. I have bound it in hte UMG widget. See below. It compiles in the UMG and the parent class is correct. I have other widgets that do work and are built the same way.
void UInventoryPanelWidget::RefreshInventory()
{
if(InventoryReference && InventoryItemSlotWidgetClass)
{
if(CapacityInfo)
{
UE_LOG(LogTemp, Error, TEXT("CapacityInfo is null!"));
return;
}
if(Items)
{
UE_LOG(LogTemp, Error, TEXT("Items is null!"));
return;
}
Items->ClearChildren();
for(UItemBase* const& InventoryItem : InventoryReference->GetInventoryContents())
{
UInventoryItemSlotWidget* ItemSlot = CreateWidget<UInventoryItemSlotWidget>(this, InventoryItemSlotWidgetClass);
ItemSlot->SetItemReference(InventoryItem);
Items->AddChildToWrapBox(ItemSlot);
}
SetInfoText();
}
}
The RefreshInventory is called by delegate, maybe this is some context issue?
Any ideas is really appreciated.
Must be initialized with nullptr. UWrapBox* Items = nullptr;
This is not a null check. You could say if (!Items)
or better if (Items == nullptr)
or for a UObject much better if (!IsValid(Items))
1 Like
Yes, now when i run i get crash instead. So this is how it all began for me lol. I thought it was because of null in binding but its something else:
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000000000004c0
UnrealEditor_MyProject!UInventoryTooltipWidget::NativeConstruct() [C:\Users\danie\Documents\Unreal Projects\MyProject\Source\MyProject\Private\UserInterface\Inventory\InventoryTooltipWidget.cpp:17]
UnrealEditor_UMG
UnrealEditor_UMG
UnrealEditor_UMG
UnrealEditor_UMG
UnrealEditor_UMG
UnrealEditor_UMG
UnrealEditor_UMG
UnrealEditor_UMG
UnrealEditor_UMG
UnrealEditor_UMG
UnrealEditor_MyProject!UInventoryPanelWidget::RefreshInventory() [C:\Users\danie\Documents\Unreal Projects\MyProject\Source\MyProject\Private\UserInterface\Inventory\InventoryPanelWidget.cpp:64]
UnrealEditor_MyProject!TBaseUObjectMethodDelegateInstance<0,UInventoryPanelWidget,void __cdecl(void),FDefaultDelegateUserPolicy>::ExecuteIfSafe() [C:\Program Files\Epic Games\UE_5.4\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:667]
UnrealEditor_MyProject!TMulticastDelegate<void __cdecl(void),FDefaultDelegateUserPolicy>::Broadcast() [C:\Program Files\Epic Games\UE_5.4\Engine\Source\Runtime\Core\Public\Delegates\DelegateSignatureImpl.inl:956]
UnrealEditor_MyProject!UInventoryComponent::HandleNonStackableItems() [C:\Users\danie\Documents\Unreal Projects\MyProject\Source\MyProject\Private\Components\InventoryComponent.cpp:156]
UnrealEditor_MyProject!UInventoryComponent::HandleAddItem() [C:\Users\danie\Documents\Unreal Projects\MyProject\Source\MyProject\Private\Components\InventoryComponent.cpp:174]
UnrealEditor_MyProject!APickup::TakePickup() [C:\Users\danie\Documents\Unreal Projects\MyProject\Source\MyProject\Private\World\Pickup.cpp:102]
UnrealEditor_MyProject!AMyPlayerCharacter::Interact() [C:\Users\danie\Documents\Unreal Projects\MyProject\Source\MyProject\Private\Player\MyPlayerCharacter.cpp:225]
UnrealEditor_MyProject!AMyPlayerCharacter::BeginInteract() [C:\Users\danie\Documents\Unreal Projects\MyProject\Source\MyProject\Private\Player\MyPlayerCharacter.cpp:189]
UnrealEditor_MyProject!TBaseUObjectMethodDelegateInstance<0,AMyPlayerCharacter,void __cdecl(void),FDefaultDelegateUserPolicy>::Execute() [C:\Program Files\Epic Games\UE_5.4\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:650]
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_EnhancedInput
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Core
UnrealEditor_Core
UnrealEditor_Core
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
kernel32
ntdll
RefreshInventory function:
void UInventoryPanelWidget::RefreshInventory()
{
if(InventoryReference && InventoryItemSlotWidgetClass)
{
if(!CapacityInfo)
{
UE_LOG(LogTemp, Error, TEXT("CapacityInfo is null!"));
return;
}
if(!Items)
{
UE_LOG(LogTemp, Error, TEXT("Items is null!"));
return;
}
Items->ClearChildren();
for(UItemBase* const& InventoryItem : InventoryReference->GetInventoryContents())
{
UInventoryItemSlotWidget* ItemSlot = CreateWidget<UInventoryItemSlotWidget>(this, InventoryItemSlotWidgetClass);
ItemSlot->SetItemReference(InventoryItem);
Items->AddChildToWrapBox(ItemSlot);
}
SetInfoText();
}
}
Omg, i found it. The stacktrace told me the issue. Sorry for being so bad lol. Thansk for quick answer!
system
(system)
Closed
June 17, 2024, 2:24pm
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.