The problem that I am facing is that the widget won’t appear after dragging.
With all header files included without error.
The class which is derived from UDragDropOperation
UCLASS()
class UI_PUBG_API UCustom_drag_drop_operation : public UDragDropOperation
{
GENERATED_BODY()
public:
UItem_Slot_UI* p_slot_UI = nullptr;
Fs_slot_item_data item_data;
bool is_weapon = false;
};
From widget class where the slot will appear
OnMouseButtonDown
Super::NativeOnMouseButtonDown(_geometry, _mouse_event);
if(_mouse_event.IsMouseButtonDown(EKeys::LeftMouseButton))
{
m_is_clicked = true;
ABase_interaction* p_tmp_weapon = Get_weapon();
int index = 0;
if(p_tmp_weapon)
{
switch (m_selected_weapon_index)
{
case 1: case 2: case 3:
if (auto p_tmp_gun = Cast<ACore_weapon>(p_tmp_weapon))
m_item_data = Fs_slot_item_data(p_tmp_gun->object_type, (int)p_tmp_gun->weapon_type);
break;
case 4:
if (auto p_tmp_melee = Cast<ACore_melee_weapon>(p_tmp_weapon))
m_item_data = Fs_slot_item_data(p_tmp_melee->object_type, (int)p_tmp_melee->weapon_type);
break;
case 5:
if (auto p_tmp_throwable = Cast<ACore_throwable_weapon>(p_tmp_weapon))
m_item_data = Fs_slot_item_data(p_tmp_throwable->object_type, (int)p_tmp_throwable->weapon_type);
break;
}
}
Highlight_img->SetColorAndOpacity(FLinearColor{ 1.f,1.f,1.f,0.35f });
}
NativeOnDragDetected
Super::NativeOnDragDetected(_geometry, _mouse_event, _out_operation);
auto p_drag_drop_operation = NewObject<UCustom_drag_drop_operation>();
auto p_slot = CreateWidget<UItem_Slot_UI>(GetWorld(), UItem_Slot_UI::StaticClass());
if (!p_slot)
return;
p_slot->Init();
p_slot->SetVisibility(ESlateVisibility::Visible);
p_slot->Item_img->SetBrushFromTexture(Cast<UTexture2D>(AUI_manager::map_inventory_weapon_ui_tex[m_item_data.image_index]));
p_slot->Name_txt->SetText(FText::FromString(m_item_data.name));
p_slot->Count_txt->SetText(FText::FromString(FString::FromInt(1)));
p_drag_drop_operation->p_slot_UI = p_slot;
p_drag_drop_operation->DefaultDragVisual = p_slot;
p_drag_drop_operation->Payload = p_slot;
p_drag_drop_operation->Pivot = EDragPivot::MouseDown;
p_drag_drop_operation->Offset = _geometry.AbsoluteToLocal(_mouse_event.GetScreenSpacePosition());
p_drag_drop_operation->is_weapon = true;
p_drag_drop_operation->item_data = m_item_data;
m_item_data = Fs_slot_item_data();
p_slot->AddToViewport();
_out_operation = p_drag_drop_operation;
And finally the slot cpp
void UItem_Slot_UI::NativeOnListItemObjectSet(UObject* _p_obj)
{
auto p_tmp_item = Cast<UItem_Slot_UI>(_p_obj);
if (p_tmp_item)
{
Item_img->SetBrushFromTexture(Cast<UTexture2D>(AUI_manager::map_inventory_weapon_ui_tex[p_tmp_item->item_data.image_index]));
Name_txt->SetText(FText::FromString(p_tmp_item->item_data.name));
Count_txt->SetText(FText::FromString(FString::FromInt(p_tmp_item->item_data.count)));
item_data = Fs_slot_item_data();
}
}
void UItem_Slot_UI::Init()
{
Item_img = NewObject<UImage>();
Name_txt = NewObject<UTextBlock>();
Count_txt = NewObject<UTextBlock>();
}
Debugged and all the values without problem but the widget just won’t appear
what am I doing wrong here? Tried adding payload but not working at all.