Changing HUD otside of Character class does not work

So i recently started to try to make multiple hud instances for different sitruations, but i’ve come across the problem: whenever i am trying to change hud state outside of Character class it just doesnt work. Here is the code:


void AIgoraCharacter::ToggleCraftingBench()
{
AIgoraGameState* GameState = Cast<AIgoraGameState>(GetWorld()->GetGameState());
AIgoraPlayerControllerBase* Controller = Cast<AIgoraPlayerControllerBase>(GetController());
UE_LOG(LogTemp, Warning, TEXT("Number of items in the invenory of %s"), *Controller->GetName())
if (GameState->GetHUDState() == GameState->HS_Ingame_Default)
{
GameState->ChangeHUDState(GameState->HS_Crafting_Bench);
Controller->bAtCraftingBench = 1;
Controller->bShowMouseCursor = true;
Controller->SetIgnoreLookInput(true);
UE_LOG(LogClass, Log, TEXT("Crafting Bench HUD was created"));
}
else
{
GameState->ChangeHUDState(GameState->HS_Ingame_Default);
Controller->bAtCraftingBench = 0;
Controller->bShowMouseCursor = false;
Controller->SetIgnoreLookInput(false);
UE_LOG(LogClass, Log, TEXT("Default HUD was created"));
}
}

And there is how i access it:


void ACraftingTable::Interact_Implementation(AIgoraPlayerControllerBase* Controller)
{
    AIgoraCharacter* Character = Cast<AIgoraCharacter>(Controller->GetCharacter());
    Character->ToggleCraftingBench();
}

At first i tried to change hudstate inside the interact_implementation, but since it did not work, i tried to make it similar to my ToggleInventory function, whis is literally same function as ToggleCraftingBench, but called via hotkey. so i copied it into the Character calss. ToggleCraftingBench starts to work when i use hotkey to call it, but thats not what i need. At this point it is just printing the log, so it comes inside the if statement, and on the second call it comes into else statement, so HUDstate is actually chaning, but nothing is happening, mouse Mouse cursor dont appear/disappear and IgnoreLookOutput does nothing either. And it is also getting the right Controller.

HUD is for local player controller. Verify blow.



AController::IsLocalPlayerController

APawn::IsLocallyControlled


Okay, i checked, it stops being local player the moment i call server function, even though i use local controller pointer as server function parameter, how do i work around it?

What i mean is:


void AIgoraCharacter::Interact()
{
    CameraStartLoc = FirstPersonCameraComponent->GetComponentLocation();
    CameraRot = FirstPersonCameraComponent->GetComponentRotation();
    AIgoraPlayerControllerBase* Controller = Cast<AIgoraPlayerControllerBase>(GetController());
    if (Controller->IsLocalPlayerController() || Controller->IsLocalController())
        UE_LOG(LogClass, Log, TEXT("1"));
    ServerInteract(CameraStartLoc, CameraRot, Controller);
}


void AIgoraCharacter::ServerInteract_Implementation(FVector StartLocation, FRotator CameraRotation, AIgoraPlayerControllerBase* Controllerr)
{
    if (Role == ROLE_Authority)
    {
        if (Controllerr->IsLocalPlayerController() || Controllerr->IsLocalController())
            UE_LOG(LogClass, Log, TEXT("2"));

“1” is logged, “2” is not.

IsLocalController works differently on Client vs (Listen) Server because of RemoteRole. Checking IsLocalController on client(listen server) is enough.



bool AController::IsLocalController() const
{
    const ENetMode NetMode = GetNetMode();

    if (NetMode == NM_Standalone)
    {
        // Not networked.
        return true;
    }

    if (NetMode == NM_Client && Role == ROLE_AutonomousProxy)
    {
        // Networked client in control.
        return true;
    }

    if (GetRemoteRole() != ROLE_AutonomousProxy && Role == ROLE_Authority)
    {
        // Local authority in control.
        return true;
    }

    return false;
}


https://docs.unrealengine.com/en-US/…les/index.html

Changing bShowMouseCursor on server does not replicated to client. Using local controller pointer is ok but make sure replication.

More reads
https://wiki.unrealengine.com/Replication
http://cedric-neukirchen.net/Downloa…Neukirchen.pdf

Well, i have tried to replicate Controller as i did with other variables, using DOREPLIFETIME, but it is still not working. Also it is not about role checking itself, but about changing hud/controller states using chain of server functions, and i still cant figure out how to do it, though it should be pretty basic thing to do.