Hi
Im trying to build a small application in which I run a dedicated server and I have two clients with a simple hud.
This hud is made with two buttons.
“Join blue team”
“Join red team”
When they press one of the two they will swap their hud to the specific one depending on the blue and the red one.
that is how it should work.
But right now, if I press in one client “red” and in the other “Blue” one of the two clients receive both HUDs and the other none. Also I print one message “Button clicked!” and every time one of the two press it both receive the message.
The code is like that:
Construct:
`void SDB_XWidget::Construct(const FArguments& InArgs)
{
OwnerHUD = InArgs._OwnerHUD;
CurrentPlayerController = Cast<ADB_XPlayerController>(OwnerHUD->PlayerOwner);
FightContainer = SNew(SHorizontalBox);
InitializeFightHUD();
ChildSlot
.VAlign(VAlign_Fill)
.HAlign(HAlign_Fill)
[
SNew(SOverlay)
+SOverlay::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Center)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
[
SNew(SButton)
.Text(FText::FromString("Blue Team!!"))
.OnClicked(this, &SDB_XWidget::HUDDefaultBehaviour, EHUDState::HUD_Construct)
.DesiredSizeScale(FVector2D(2, 2))
]
]
+ SOverlay::Slot()
.HAlign(HAlign_Right)
.VAlign(VAlign_Center)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
[
SNew(SButton)
.Text(FText::FromString("Red Team!!"))
.OnClicked(this, &SDB_XWidget::HUDDefaultBehaviour, EHUDState::HUD_Basic)
.DesiredSizeScale(FVector2D(2, 2))
]
]
];`,
Method that gets called on clicked
FReply SDB_XWidget::HUDDefaultBehaviour(EHUDState NewHUDState)
{
switch (NewHUDState)
{
case EHUDState::HUD_Basic:
CurrentPlayerController->OwnTeam = EPlayerTurn::T_P1;
GEngine->GameViewport->AddViewportWidgetContent(FightContainer.ToSharedRef());
break;
case EHUDState::HUD_Construct:
CurrentPlayerController->OwnTeam = EPlayerTurn::T_P2;
GEngine->GameViewport->AddViewportWidgetContent(ConstructContainer.ToSharedRef());
break;
}
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Button Clicked!"));
return FReply::Handled();
}
None of this method is Server / Client only, or anything like that. I believe that may be the issue but I don´t quite understand why since this is a particular thing that only the client should care about.
Can anybody help me with this?
Thanks!