Problems with interface: 'override' did not override any base class methods

Hey guys.

I’ve researched for hours on a solution to my current problem, but I can’t seem to find any solution. To quickly explain what I’m going for: I’ve made a interface for events, and I’m trying to inherit the interface on my custom GameState, so the GameState updates my in-game time and date speed multiplier.

When inherting I’m defining the base function as well as the override ‘_Implementation’ functionas my interface functions are BlueprintImplementableEvent. It’s easier to show than tell.

Interface:

#pragma once

#include "./Machines/ConstructableMaster.h"
#include "HUDInterface.generated.h"

// This class does not need to be modified.
UINTERFACE()
class UHUDInterface : public UInterface
{
	GENERATED_UINTERFACE_BODY()
};

/**
 * 
 */
class COMPTECH_API IHUDInterface
{
	GENERATED_IINTERFACE_BODY()

public:
	UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
	void ConstructMachine(TSubclassOf<AConstructableMaster> Constructable);

	UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
	void UpdateGameSpeed(float Multiplier);	
};

It’s the function void UpdateGameSpeed(float Multiplier) that I wish to listen to.
Here’s my GameState and my implementation of the function:

GameState.h

#pragma once

#include "GameFramework/GameStateBase.h"
#include "Interfaces/HUDInterface.h"
#include "ComptechGameState.generated.h"

/**
 * 
 */
UCLASS()
class COMPTECH_API AComptechGameState : public AGameStateBase, public IHUDInterface
{
	GENERATED_BODY()
	
public:
	// Constructor
	AComptechGameState();
	
protected:
	UFUNCTION()
	virtual void BeginPlay() override;

	UFUNCTION()
	virtual void Tick(float DeltaTime) override;

public: 
	/** HUD interface **/
	UFUNCTION(BlueprintNativeEvent)
	void UpdateGameSpeed(float Multiplier);
	virtual void UpdateGameSpeed_Implementation(float Multiplier) override;

};

All guides I’ve found shows this solution. When I implement this function in my .cpp, I get the following error:

'AComptechGameState::UpdateGameSpeed_Implementation': method with override specifier 'override' did not override any base class methods

Here’s my implementation

GameState.cpp

#include "Comptech.h"
#include "ComptechGameState.h"

AComptechGameState::AComptechGameState()
{
	// Game state should tick, and start with tick
	PrimaryActorTick.bStartWithTickEnabled = true;
	PrimaryActorTick.bCanEverTick = true;
}

void AComptechGameState::BeginPlay()
{
	Super::BeginPlay();
}

void AComptechGameState::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

// Update game speed from HUD interface
void AComptechGameState::UpdateGameSpeed_Implementation(float Multiplier)
{
	TimeUnit = DefaultGameSpeed * Multiplier;
	//OnUpdateGameSpeedDelegate.Broadcast(TimeUnit);
}

I’m hoping that some of you guys could perhaps tell me what the issue is, since I’m at a loss and cannot see what’s wrong. :confused:

NOTE:
I’ve left in the ConstructMachine since this WORKS. This is why I’m mostly confused. ConstructMachine works but UpdateGameSpeed doesn’t. The GameState does not override the ConstructMachine but I’ve managed to get that working just as a test

So I want to make my interface function virtual (you didn’t do that in your code example, but explained it later) and simply remove the _Implementation function and replace it with the base function + override modifier?

The problem with this is also that it requires me to override every single function in the interface, but I’m not interested in that. Is that considered bad practice, and should I split up the interface into multiple interfaces to resolve this issue?

I know that’s what interfaces are, I guess I’m just a bit consfused at the moment, since this actually makes sense. I might be comparing this a bit to much with BlueprintInterfaces from the editor. In those interfaces, I can make some functions that other blueprints can inherit, but not all are required, they are here. Is that correct understood, and in that case, how can I create something just like blueprint interfaces? I feel like I’m missing some crucial part.

If you want to have a C++ implementation for your UInterface methods just change your UFUNCTION BlueprintImplementationEvent specifier to BlueprintNativeEvent. This way UHT will generate YourMethod_Implementation declaration at compile time. That’s the virtual method you will override in C++ child classes.

#pragma once

 #include "HUDInterface.generated.h"


 // This class does not need to be modified.
 UINTERFACE()
 class UHUDInterface : public UInterface
 {
     GENERATED_UINTERFACE_BODY()
 };
 
 /**
  * 
  */
 class COMPTECH_API IHUDInterface
 {
     GENERATED_IINTERFACE_BODY()
 
 public:

     UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
     void UpdateGameSpeed(float Multiplier);    
 };

In the class implementing the interface override “UpdateGameSpeed_Implementation” and implement it as you want.

#pragma once
 
 #include "GameFramework/GameStateBase.h"
 #include "Interfaces/HUDInterface.h"
 #include "ComptechGameState.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class COMPTECH_API AComptechGameState : public AGameStateBase, public IHUDInterface
 {
     GENERATED_BODY()
     
 public:
     // Constructor
     AComptechGameState();
     
 protected:
     UFUNCTION()
     void BeginPlay() override;
 
     UFUNCTION()
     void Tick(float DeltaTime) override;
 
 public: 
     /** HUD interface **/
     void UpdateGameSpeed_Implementation(float Multiplier) override;
 };

Implementation:

#include "Comptech.h"
    #include "ComptechGameState.h"
     
     AComptechGameState::AComptechGameState()
     {
         // Game state should tick, and start with tick
         PrimaryActorTick.bStartWithTickEnabled = true;
         PrimaryActorTick.bCanEverTick = true;
     }
     
     void AComptechGameState::BeginPlay()
     {
         Super::BeginPlay();
     }
     
     void AComptechGameState::Tick(float DeltaTime)
     {
         Super::Tick(DeltaTime);
     }
     
     // Update game speed from HUD interface
     void AComptechGameState::UpdateGameSpeed_Implementation(float Multiplier)
     {
         TimeUnit = DefaultGameSpeed * Multiplier;
         //OnUpdateGameSpeedDelegate.Broadcast(TimeUnit);
     }

Hope it helps!

Yes, sorry, I will correct that right now.

Interfaces are that, a set of pure virtual functions that describes the structure that the child classes should have.
If you want to have a base implementation then do not use interfaces, just use a normal class instead.

Sorry I thought that you wanted to use it purely in C++ as your example showed that, didn’t realize that it was a UInterface.

If you want to be able to use your interface in blueprints as well as having an implementation in C++ then use BlueprintNativeEvent instead of BlueprintImplementableEvent for your methods in the interface declaration.

Then in the child class C++ implementation override YourMethod_Implementation (this method declaration is automatically generated by UHT at compile time)

Also make the method BlueprintCallable if you want to be able to call it from blueprints too.

Sorry for the misunderstanding. I will update my answer.

Perhaps I sould be using delegates for this kind of event. I’m not really interested in using these functions in my blueprint anyways. Basically I just want various actors and widgets to update their game time variable whenever the game time is changes. Am I better off using delegates for this kind of event?

Yes! Delegates are the simplest and most elegant way to do event driven logic in UE.