Download

Help with Interfaces

Hi All I’m needing some extra in-depth explanation as to how to use Unreal’s Interfaces.

Currently I’ve used the following example: Interfaces | Unreal Engine Documentation

I’ve made the ReactToTriggerInterface and ATrap classes/headers, and pasted in the appropriate code, however it won’t compile and generates errors:


\Source\SpaceProject/ATrap.h(25) : error C3668: 'AATrap::ReactToTrigger': method with override specifier 'override' did not override any base class methods
\Source\SpaceProject\ATrap.h(25) : error C3668: 'AATrap::ReactToTrigger': method with override specifier 'override' did not override any base class methods

I’ve spent a few hours on this, and managed to get a working interface following a different guide (A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums), but its quite different and doesn’t provide any base functionality from within the interface class which is what I’m after…

I’ll share what code I’m struggling with below;

](ATrap.cpp - Pastebin.com)

As a workaround to using Interfaces, I could use a normal data driven class (UObject) with default methods I can implement and override…but then again whats the point of the interface if I do that right.

Any guidance is appreciated!

Hi,
Your ATrap must inherites the interface, aka:

ATrap.h:



// Fill out your copyright notice in the Description page of Project Settings.



#pragma once



#include "CoreMinimal.h"

#include "GameFramework/Actor.h"

#include "ATrap.generated.h"



UCLASS()

class SPACEPROJECT_API AATrap : public AActor, public IReactToTriggerInterface

...]


The error makes sense, because Atrap cannot overridee a method it never heard about :slight_smile:
Implementing the interface should solve that.

Thanks for the answer. It turns out not only did I miss some code in my examples, I also wasn’t understanding interfaces correctly and had been trying to do what abstract classes achieve.