Announcement

Collapse
No announcement yet.

Changing HUD otside of Character class does not work

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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:
    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:

    Code:
    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.
    Last edited by LUTEISHIY; 11-10-2019, 10:44 AM.

    #2
    HUD is for local player controller. Verify blow.

    Code:
    AController::IsLocalPlayerController
    
    APawn::IsLocallyControlled

    Comment


      #3
      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:

      Code:
      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);
      }
      Code:
      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.
      Last edited by LUTEISHIY; 11-12-2019, 12:05 PM.

      Comment


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

        Code:
        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
        Role/RemoteRole Reversal


        Role and RemoteRole could be reversed depending on who is inspecting these values. For example, if on the server you have this configuration:
        • Role == ROLE_Authority
        • RemoteRole == ROLE_SimulatedProxy

        Then the client would see it as this:
        • Role == ROLE_SimulatedProxy
        • RemoteRole == ROLE_Authority
        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
        Last edited by empty2fill; 11-13-2019, 02:04 AM.

        Comment


          #5
          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.

          Comment

          Working...
          X