c:\program files\unreal engine\4.7\engine\source\runtime\coreuobject\public\uobject\UObject.h(81): error C2440: 'static_cast' : cannot convert from 'UObject *' to 'UWidgetComponent *'
Any idea how to fix that? I’m a bit confused as well since, according to the api doc, UObject is a parent class of UObjectComponent so the casting should work.
Or is that not the right way to initialize that object?
I tried a different approach which lead me to where I am now.
Actually it turned out exactly as I wanted It to be:
.h
// The class that will be used for the Items Nameplate
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = UI)
TSubclassOf<class UUserWidget> NameplateUIClass;
// The instance of the players Inventory UI Widget
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = UI)
class UUserWidget* NameplateWidget;
.ccp
if (NameplateUIClass)
{
if (!NameplateWidget)
{
NameplateWidget = CreateWidget<UUserWidget>(GetWorld()->GetGameInstance(), NameplateUIClass);
if (!NameplateWidget)
{
return;
}
NameplateWidget->AddToViewport();
NameplateWidget->SetVisibility(ESlateVisibility::Hidden);
}
}
This allows me to control the widget via code and I may use the editor to design the widget itself. You have to create that widget(class) within the editor however. Values can be exchanged via blueprint get and set.