As it's said, in UE 4.27 widget component doesn't show up when its outer is player controller. But in 4.18 version it worked.
Could you please explain why ?
And how ( if it's possible ) can I make it work in 4.27 ?
Widget is set in the widget component.
To reproduce:
.h:
UPROPERTY(EditDefaultsOnly)
TSubclassOf<UComicFXWidgetComponent> ComicWidgetClass;
UComicFXWidgetComponent* NewComponent;
My .cpp code that does work:
"BeginPlay":
// If I change "this" with PlayerController ref then it will not work
NewComponent = NewObject<UComicFXWidgetComponent>(this, ComicWidgetClass);
NewComponent->RegisterComponent();
"InteractButtonPressed":
NewComponent->AttachToComponent(equippedWeapon_->mesh_, FAttachmentTransformRules::SnapToTargetNotIncludingScale, TEXT("DamageSocket"));
My .cpp code that does NOT work:
"BeginPlay":
APlayerController* PC = UGameplayStatics::GetPlayerController(this, 0);
NewComponent = NewObject<UComicFXWidgetComponent>(PC, ComicWidgetClass); // "this" replaced with "PC"
NewComponent->RegisterComponent();
"InteractButtonPressed":
NewComponent->AttachToComponent(equippedWeapon_->mesh_, FAttachmentTransformRules::SnapToTargetNotIncludingScale, TEXT("DamageSocket"));
Okay. The answer is:
APlayerController derives from AController. And AController in it's constructor calls SetHidden(true);
and it affects it's children ( or actors whose outer is the controller ).
To solve just add in your Controller constructor:
SetActorHiddenInGame(false);