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.
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?
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.