Download

Very Basic UFUNCTION Issue

Greetings! Super-simple issue but … I am trying to call a function from a custom game mode in Blueprints.

In my game mode .h:



public:
	UFUNCTION(BlueprintCallable, Category="Test")
	void AddNewGame();


In my game mode .c:



void AMainGameMode::AddNewGame(){
	UE_LOG(LogTemp, Error, TEXT("OKAY WORKING"));


I then edited the level blueprint to create a basic test UI. I added a button that, when pressed, is supposed to trigger the function, but doesn’t. The blueprints look like:

img1.PNG

Here is the reference to the game mode object in blueprints:

img2.PNG

The button works fine and the game mode is being loaded just fine; I can put the function in the constructor and it outputs correctly.

Does anyone know what is going on here? Thanks!

Are you filling the MainGameMode variable with the current game mode?

Use the Get GameMode node and cast to your custom mode.