Waredun
(Waredun)
May 21, 2024, 5:40pm
1
I need to get like on screenshot.
My code in HUD
AMyHUD::AMyHUD() : Super()
{
ConstructorHelpers::FClassFinder<UUserWidget> WBP_Player(TEXT("/Game/MyGameFolder/HUD/Player/WBP_Player"));
ConstructorHelpers::FClassFinder<UUserWidget> WBP_WeaponC(TEXT("/Game/MyGameFolder/HUD/Weapon/WBP_WeaponC"));
MainHUD = WBP_Player.Class;
WeaponHUD = WBP_WeaponC.Class;
}
void AMyHUD::BeginPlay()
{
Super::BeginPlay();
CharacterWidget = CreateWidget(GetWorld(), MainHUD);
WeaponWidget = CreateWidget(GetWorld(), WeaponHUD);
CharacterWidget->AddToViewport();
}
I nned to use weaponwiget ref in weapon script
void AWeapon::SetWeaponWidgetRef(UWeaponWidget* WeaponWidget)
{
WeaponWidgetRef = WeaponWidget;
}
void AWeapon::UpdateWidgetInfo()
{
WeaponWidgetRef->UpdateWeaponWidgetInfo(ammoMagazine, currentAmmo,weaponIcon);
}
I want to get ref from getplayercontroller->getHUD
but in my HUD I can’t get ref to UWeaponWidget* how to do it
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
MyWeapon->SetWeaponWidgetRef(Cast<AMyHUD>(PlayerController->GetHUD())->WeaponWidget);
OR
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
MyWeapon->SetWeaponWidgetRef(PlayerController->GetHUD<AMyHUD>()->WeaponWidget);
Waredun
(Waredun)
May 23, 2024, 11:12am
3
I was able to do this. The problem is that my weapon widget is UUserWidget* since the CreateWidget() function returns in this format, but I need it to be UWeaponWidget*
Waredun
(Waredun)
May 23, 2024, 11:16am
4
type argument UUserWidget* is incompatible with type parameter UWeaponWidget*
Then change the type of WeaponWidget to the correct type of UWeaponWidget* (or preferably TObjectPtr< UWeaponWidget >) in your property and then use this:
WeaponWidget = Cast<UWeaponWidget>(CreateWidget(GetWorld(), WeaponHUD));
system
(system)
Closed
June 23, 2024, 1:57pm
7
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.