MenuInterface hides class member

I know that there is a closed thread about this, but i am unable to understand how to fix it. i have downloaded the file from github, i have copied the text from online and pasted it into visual studio 2019 (v 4.8.03752)and all times i get the C4458 error.

void UMainMenu::SetMenuInterface(IMenuInterface* MenuInterface)
{
    this->MenuInterface = MenuInterface;
}

void UMainMenu::HostServer()
{
    UE_LOG(LogTemp, Warning, TEXT("Host Button clicked"));
    if (MenuInterface != nullptr)
    {
        MenuInterface->Host();
    }
}

I have tried renaming all the MenuInterface pointers (links) to AMenuInterface and it builds but nothing happens

void UMainMenu::SetMenuInterface(IMenuInterface* MenuInterface)
{
    this->AMenuInterface = MenuInterface;
}

void UMainMenu::HostServer()
{
    UE_LOG(LogTemp, Warning, TEXT("Host Button clicked"));
    if (AMenuInterface != nullptr)
    {
        AMenuInterface->Host();
    }
}

Any kind of help would be great, even if it is just remake this point of the video for future people

Thanks

1 Like

Seems like you are probably getting a compilation warning and that is not the actual issue. Could you give us a bit more context to what you are expecting and what isn’t happening?

If I have the code like what is in the video and save it in VS. When ue4 starts up, the app crashes on startup and the only way I have been able to fix it is by having the code like in the second code layout.

That’s what I am finding let’s VS compile and for ue4 to start up and run the game. Will be happy to upload a copy of both files (one that crashes ue4 and one that dosent crash ue4) to make looking into the problem easy

Hey @crash987,
I stumbled upon the same problem you had and I am not quite sure why this is happening, hopefully with some extra context @sampattuzzi can tell us what is going on here, as I am quite curious as to why this is happening.
I did however manage to fix it by naming the IMenuInterface* parameter to something else than the name of the local IMenuInterface* variable.

Some screenshots:
MainMenu.h:
Knipsel

MainMenu.cpp:
Knipsel1

Original compiler error message:

Hope this helps!

This is what is stopping me from continuing doing the course, I am really loving it, just a shame there seems to be no or little help on fixing it. I think this part needs a rework so others don’t have the same problem

Could you show me your MainMenu.h?

Also, this->AMenuInterface = MenuInterface; is not necessary as the parameter is not named the same as the local variable. So AMenuInterface = MenuInterface; should be fine.

Make sure to delete your binaries and intermediates folders to make sure the compilation is up-to-date.

Hi Sam, i have just tried your idea of deleting the binaries and intermediates folder for the project, still getting the same problem “Error C4458 declaration of ‘MenuInterface’ hides class member”.

Is there a workaround that would get this fixed

so i have changed the code to how @Kobro has his code and i still have the same problem. what i had added in to the if null checker is a uelog to say if the host button to the game was valid or not.
Capture

so i now know that when the host button is pressed, MenuInterface is not valid and will not proceed to the game. With my very limited knowledge of cpp (or any) programming, i am now needing to find out where in the code it is braking and not working

When you load the menu in the game instance do you set the interface like this:

afbeelding

Because your warning leads me to believe the MenuInterface is not set.

I’ll have to have a look when I get home, from memory the code is all there but will have to have a second look

EDIT:
it looks like i was missing the set menu interface in the PuzzlePlatformGameInstance.cpp, sadly i am still having the same problem. I will post the code here of what i have and hope there is something easy that i have missed

MainMenu cpp

bool UMainMenu::Initialize()
{
    bool Success = Super::Initialize();
    if (!Success) return false;

    if (!ensure(Host != nullptr)) return false;
    Host->OnClicked.AddDynamic(this, &UMainMenu::HostServer);
    Join->OnClicked.AddDynamic(this, &UMainMenu::JoinServer);
   return true;
}

void UMainMenu::SetMenuInterface(IMenuInterface* MMenuInterface)
{
    MenuInterface = MenuInterface;
}

void UMainMenu::JoinServer()
{
    UE_LOG(LogTemp, Warning, TEXT("Joining a game"));

}

void UMainMenu::Setup()
{
    this->AddToViewport();
    
    UWorld* World = GetWorld();
    if (!ensure(World != nullptr)) return;

    APlayerController* PlayerController = World->GetFirstPlayerController(); //get player controller
    if (!ensure(PlayerController != nullptr)) return;
    
    FInputModeUIOnly InputModeDate; // create input function

    InputModeDate.SetWidgetToFocus(this->TakeWidget()); //make Menu focus
    InputModeDate.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock); //bring mouse into menu

    PlayerController->SetInputMode(InputModeDate); //alow mouse inputs in menu
    PlayerController->bShowMouseCursor = true; //show mouse in menu
}

void UMainMenu::TearDown()
{
    this->RemoveFromViewport();

    UWorld* World = GetWorld();
    if (!ensure(World != nullptr)) return;

    APlayerController* PlayerController = World->GetFirstPlayerController(); //get player controller
    if (!ensure(PlayerController != nullptr)) return;
    FInputModeGameOnly InputModeData;
    PlayerController->SetInputMode(InputModeData);
    PlayerController->bShowMouseCursor = false; //don't show mouse in menu
}

void UMainMenu::HostServer()
{
    UE_LOG(LogTemp, Warning, TEXT("Host Button clicked"));
    if (MenuInterface != nullptr)
    {
        UE_LOG(LogTemp, Warning, TEXT("MenuInterface is valid"));
        MenuInterface->Host();
    }
    else
    {
        UE_LOG(LogTemp, Warning, TEXT("MenuInterface is not valid"));
    }
}

MainMenu h

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "MenuInterface.h"
#include "Engine/World.h"
#include "MainMenu.generated.h"

/**
 * 
 */
UCLASS()
class PUZZLEPLATFORMES_API UMainMenu : public UUserWidget
{
	GENERATED_BODY()

public:

	void SetMenuInterface(IMenuInterface* MMenuInterface);

	void Setup();

	void TearDown();

protected:
	virtual bool Initialize();


private:
	UPROPERTY(meta = (BindWidget))
	class UButton* Host;

	UPROPERTY(meta = (BindWidget))
	class UButton* Join;

	UFUNCTION()
	void HostServer();

	UFUNCTION()
	void JoinServer();

	IMenuInterface* MenuInterface = nullptr;
	
};

PuzzlePlatformGameInstance cpp

#include "PuzzlePlatformGameInstance.h"
#include "UObject/ConstructorHelpers.h"
#include "MenuSystem/MainMenu.h"

#include "Engine/Engine.h"
#include "Blueprint/UserWidget.h"
#include "PlatformTrigger.h"

UPuzzlePlatformGameInstance::UPuzzlePlatformGameInstance(const  FObjectInitializer& FObjectInitializer)
{
	ConstructorHelpers::FClassFinder<UUserWidget> MenuBPClass(TEXT("/Game/Menu_System/WBP_MainMenu")); //reading BluePrint from UE4
	if (!ensure(MenuBPClass.Class != nullptr)) return;
	MenuClass = MenuBPClass.Class;
}

void UPuzzlePlatformGameInstance::Init()
{
	UE_LOG(LogTemp, Warning, TEXT("Found class %s"), *MenuClass->GetName());

}

void UPuzzlePlatformGameInstance::LoadMenu()
{
	if (!ensure(MenuClass != nullptr)) return;
	Menu = CreateWidget<UMainMenu>(this, MenuClass);
	if (!ensure(Menu != nullptr)) return;
	
	Menu->Setup();
	Menu->SetMenuInterface(this);
}

void UPuzzlePlatformGameInstance::Host()
{
	if (Menu != nullptr)
	{
		Menu->TearDown();
	}

	UEngine* Engine = GetEngine();
	if (!ensure(Engine != nullptr)) return;

	Engine->AddOnScreenDebugMessage(0, 3, FColor::Red, TEXT("Hosting"));
	
	UWorld* World = GetWorld();
	if (!ensure(World != nullptr)) return;

	World->ServerTravel("/Game/ThirdPersonCPP/Maps/ThirdPersonExampleMap?listen"); //server levle travel

}

void UPuzzlePlatformGameInstance::Join(const FString& Address)
{
	UEngine* Engine = GetEngine();
	if (!ensure(Engine != nullptr)) return;

	Engine->AddOnScreenDebugMessage(0, 5, FColor::Green, FString::Printf(TEXT("Joining %s "), *Address));
	// client levle travel
	APlayerController* PlayerController = GetFirstLocalPlayerController();
	if (!ensure(PlayerController != nullptr)) return;

	PlayerController->ClientTravel(Address, ETravelType::TRAVEL_Absolute);
	

}

In MainMenu.cpp:

void UMainMenu::SetMenuInterface(IMenuInterface* MMenuInterface)
{
    MenuInterface = MenuInterface;
}

Should be

void UMainMenu::SetMenuInterface(IMenuInterface* MMenuInterface)
{
MenuInterface = MMenuInterface;
}

Otherwise you are setting the variable to itself :wink:

Big thanks for that. i thought i had changed the MenuInterface = MMenuInterface to that. I suppose it’s a good idea to always have a second set of eyes to help with other peoples code, and to also not code when your tired.

Again big thanks @Kobro for your help

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.