Another day, another question.
Anyway, I am currently working on spawning UImage elements through C++ for use in an HUD (for the sake of a minimap. I want to dynamically be able to add and remove enemies, so I really don’t want to resort having to put the images into the HUD one by one). While I can get the UImage to spawn (I have double checked and it does seem like the object is getting properly spawned; it doesn’t return NULL values at the very least), it just doesn’t show up in the HUD when I am playing. I have tried pretty much anything I could think off; visibility, position, scale, z-order, layout (margins, anchors) and whatnot. Nothing works. The only other thing I can think off is that it’s not being properly connected to the widget instance and therefore not being rendered, but I have no idea how to correct that.
The function itself is called through the Interface
UImage* UBK_UIWidget_Minimap::DrawPlayerOnMap(UImage* BoxOwner, UPanelWidget* OwningPanel)
{
LocalPlayer = GetOwningPlayer();
if (LocalPlayer)
{
UCanvasPanelSlot* DefSlot = ConstructObject<UCanvasPanelSlot>(UCanvasPanelSlot::StaticClass());
if (!DefSlot)
return NULL;
DefSlot->Parent = OwningPanel;
DefSlot->SetOffsets(FMargin(1600.f, 760.f, 16.f, 16.f));
FAnchors DefaultAnchorData;
DefaultAnchorData.Minimum = FVector2D(0.f, 0.f);
DefaultAnchorData.Maximum = FVector2D(1.f, 1.f);
DefSlot->SetAnchors(DefaultAnchorData);
DefSlot->SetZOrder(1);
UImage* PlayerImage = ConstructObject<UImage>(UImage::StaticClass());
if (!PlayerImage)
return NULL;
PlayerImage->Slot = DefSlot;
PlayerImage->SetBrushFromTexture(PlayerIndicatorTexture);
PlayerImage->SetRenderTransformPivot(FVector2D(0.5, 0.5));
PlayerImage->SetIsEnabled(true);
PlayerImage->SetVisibility(ESlateVisibility::Visible);
return PlayerImage;
}
return NULL;
}
Anyone knows what the problem is here?