GameModeBase SetPause LNK2001

Hi, I am getting a error when creating a GameModeBase Class (During compiling the class even if the file is unedited from when it was created)

Error CoinGameModeBase.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl AGameModeBase::SetPause(class APlayerController *,class TBaseDelegate<bool>)" (?SetPause@AGameModeBase@@UEAA_NPEAVAPlayerController@@anonymous_user_e71e0d8a?$TBaseDelegate@_N$$$V@@@Z)

Error C1.generated.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl AGameModeBase::SetPause(class APlayerController *,class TBaseDelegate<bool>)" (?SetPause@AGameModeBase@@UEAA_NPEAVAPlayerController@@anonymous_user_e71e0d8a?$TBaseDelegate@_N$$$V@@@Z)

Error F:\Projects\1\C1\Binaries\Win64\UE4Editor-C1-1981.dll : fatal error LNK1120: 1 unresolved externals

I found a workaround for it by copying the function from the actual GameModeBase class file.

Adding this to the header file of my class

public:
virtual bool SetPause(APlayerController* PC, FCanUnpause CanUnpauseDelegate = FCanUnpause());

and this to the cpp file

bool ACoinGameModeBase::SetPause(APlayerController* PC, FCanUnpause CanUnpauseDelegate /*= FCanUnpause()*/)
{
	if (AllowPausing(PC))
	{
		// Add it for querying
		Pausers.Add(CanUnpauseDelegate);

		// Let the first one in "own" the pause state
		AWorldSettings * WorldSettings = GetWorldSettings();
		if (WorldSettings->Pauser == nullptr)
		{
			WorldSettings->Pauser = PC->PlayerState;
		}
		return true;
	}
	return false;
}

And the compilation works. I am using UE 4.14.3

Hey -

The error appears to be due to the signature of your function not matching the signature of it’s parent that you are overriding. When you want to override a function that is defined in the parent class, the parameter list needs to match the parent class parameter list. You’ll also want to include a line of Super::SetPause(); if you want to call the parent implementation of the function as well as whatever code you’re using to override the function.

Cheers

I didn’t want to do anything with setpause. I downloaded unreal engine 4.14 a few days ago and this was my first project on it. All I did was create the C++ class for Game Mode Base within the editor and I got a error saying the class has been created but not added to the editor as there are some errors. It showed me the output window and i saw the same error. i listed above. By copying the function from the parent, the issue was fixed. So I am guessing there is a bug in UE that makes it behave this way. I tried creating a GameMode class and it acts the same way.

Just to be clear, I get the error right after creating the class (when UE compiles the project after creating the file and before it opens to edit the file)

It’s strange that you’re getting that message simply by creating a GameMode class. Does the same error appear if you create a game mode in a new project as well? For additional information, can you create a game mode and, assuming it gives you this error message, immediately open the project in VS and post a screenshot of what the .h and .cpp for the new game mode class looks like?

I will get back on a computer and send the other screenshots in a while.
alt text

Successfully added class ‘MyGameModeBase’, however you must
recompile the ‘MyProject’ module
before it will appear in the Content
Browser. Failed to compile newly
created game module.

Would you like to open the Output Log
to see more details?

Happens on a new project as well.

Here is the code,

As I mentioned earlier, once I copy the original code of SetPause function to this file, everything works fine. I did not edit the original source code in any way so I am not sure why it doesnt work.

I’m still not able to reproduce the error you’re getting when I create a game mode class, and the code you posted is what I would expect to see when a new class is created. Are you using a blueprint project that you’re adding code to or is the project a code project by default? Also, are you using the editor from the binary launcher or an engine built from source code? If you’re using a the launcher, please try selecting the Verify option from the dropdown menu for 4.14 in the launcher. If you’re using a source version, please try running GenerateProjectFiles.bat followed by recompiling the UE4.sln. This should ensure that the source file for GameModeBase is correct.

I created a blank blueprint project. I am using the launcher so I will verify unreal engine and post the results.

It still doesnt work. I have verified it and when I try to create a GameModeBase class I get the same error.

Inside Visual Studio, can you confirm that the [ProjectName].Build.cs file has “Engine” listed in the PublicDependencyModulesNames section? Also, does this error (or similar) appear when creating other classes?

Yes, Engine is listed there. Screenshot - aacf726e291421f420116fec62249172 - Gyazo

Every other class works fine as far as I have used.

Hello -

Sorry for the late reply. I have done additional testing but have not come across a compile fail in a when adding a GameModeBase class. Do you see the same thing in a 4.15 project? If you’re able to work around this issue by copying the SetPause() function from the GameModeBase parent class then I am going to mark this as resolved, however feel free to comment to reopen the post if you encounter this problem in the future.

Cheers

I have the same problem now that I upgraded an older project (actually the “Programming Quick Start” tutorial) from 4.14 to 4.17. I neither used SetPause() before, nor after. (“Engine” is listed…)

(NB: A solution is not important in my case as it was only a tutorial anyway, but maybe it can give a clue to why this happened.)