# Can't compile new UInterface

**URL:** <https://forums.unrealengine.com/t/cant-compile-new-uinterface/419011>\
**Category:** UI\
**Tags:** interface, unreal-engine, compile-error, UInterface, UI, UE4, CPP, question\
**Created:** [March 5, 2018, 12:23pm UTC](https://forums.unrealengine.com/t/cant-compile-new-uinterface/419011 "2018-03-05T12:23:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Craimasjien](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Craimasjien](https://forums.unrealengine.com/u/Craimasjien)\
**Post date:** [March 5, 2018, 12:23pm UTC](https://forums.unrealengine.com/t/cant-compile-new-uinterface/419011/1 "2018-03-05T12:23:24Z")

</div>

I’ve been trying to create a C++ interface [following this page of the 4.14 documentation](https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Interfaces/) to implement user interaction with actors. So, I made a a default UInterface using the `Create C++ class` wizard in the editor.  
The idea is that the `Main Character` class fires a single line trace to identify an `Actor`, get the `Actor` and check whether or not it implements my interface. If it does, fire the event on the `Actor`.  
My interface looks like this;

**MainCharacterInteraction.h**

```
#pragma once

#include "MainCharacterInteraction.generated.h"

UINTERFACE(Blueprintable)
class UMainCharacterInteraction : public UInterface
{
	GENERATED_BODY()
};

class MYAPI_API IMainCharacterInteraction
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category = "Player interaction")
	void Interact() const;
};

```

**MainCharacterInteraction.cpp**

```
void AMainCharacterInteractionActor::Interact() const
{

}

```

Now, the guide itself is quite vague about the implementation side, because it shows how to implement the interface, but not how to give any functionality to it.

**MainCharacterInteractionActor.h**

```
#pragma once

#include "CoreMinimal.h"
#include "Interfaces/Character/MainCharacterInteraction.h"
#include "MainCharacterInteractionActor.generated.h"

UCLASS()
class MYAPI_API AMainCharacterInteractionActor : public AActor, public IMainCharacterInteraction
{
    GENERATED_BODY()

public:
    AMainCharacterInteractionActor(const FObjectInitializer& ObjectInitializer);

    UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Player interaction")
    virtual void Interact() const override;
};

```

So, I’d assume that on the implementation side of the class I should do something like;

**MainCharacterInteractionActor.cpp**

```
void AMainCharacterInteractionActor::Interact() const
{

}

```

But whenever I try and compile this code (either via the `Editor -> Compile`, or `Visual Studio -> Build`) it fails with the following error:

```
MainCharacterInteractionActor.h:17:27: error: only virtual member functions can be marked 'override'

```

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![AmphDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AmphDev](https://forums.unrealengine.com/u/AmphDev)\
**Post date:** [March 5, 2018, 12:26pm UTC](https://forums.unrealengine.com/t/cant-compile-new-uinterface/419011/2 "2018-03-05T12:26:01Z")

</div>

Hello!

this should be `void Interact() const;` `virtual void Interact() const;` in your interface class

and actually you dont need const because you did not return anything…

so go ahed and use

```
virtual void Interact();
```

---

<div class="post-metadata">

**Author:** ![Craimasjien](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Craimasjien](https://forums.unrealengine.com/u/Craimasjien)\
**Post date:** [March 5, 2018, 12:34pm UTC](https://forums.unrealengine.com/t/cant-compile-new-uinterface/419011/3 "2018-03-05T12:34:16Z")

</div>

Thanks for your answer. It didn’t help though;  
If I declare the interface function as `virtual void Interact()`, I get this error: **Error: BlueprintImplementableEvents in Interfaces must not be declared 'virtual’**

---

<div class="post-metadata">

**Author:** ![AmphDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AmphDev](https://forums.unrealengine.com/u/AmphDev)\
**Post date:** [March 5, 2018, 12:50pm UTC](https://forums.unrealengine.com/t/cant-compile-new-uinterface/419011/4 "2018-03-05T12:50:06Z")

</div>

you have right sry… missed that is a blueprintimplementableEvent 🙂  
I said then wrong…

So the first problem with that… BlueprintImplementableEvents must be overrided in Blueprint!  
This is why we call them **BlueprintImplementableEvents** …

You cant override them… in C++! If you want override in c++ … so you wanna do things both in c++ code and blueprint code you shuld use **BlueprintNativeEvent**

So you cant declare interface function as blueprintimplementableevent, then override as blueprintnative event…

That must be delcared as blueprintnativeevent and when you override you must override in this form:

virtual void Interact\_Implementation() override;

Further Informations about interfaces and UFUNCTION marks:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

---

<div class="post-metadata">

**Author:** ![Craimasjien](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Craimasjien](https://forums.unrealengine.com/u/Craimasjien)\
**Post date:** [March 5, 2018, 1:56pm UTC](https://forums.unrealengine.com/t/cant-compile-new-uinterface/419011/5 "2018-03-05T13:56:54Z")

</div>

Your answer pushed me in the right direction. Thanks.

---

<div class="post-metadata">

**Author:** ![Craimasjien](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Craimasjien](https://forums.unrealengine.com/u/Craimasjien)\
**Post date:** [March 5, 2018, 2:02pm UTC](https://forums.unrealengine.com/t/cant-compile-new-uinterface/419011/6 "2018-03-05T14:02:31Z")

</div>

As it turns out, the guide I followed was specifically tailored for `BlueprintImplementableEvents`, what I needed was a `BlueprintNativeEvent`. For people that might end up with the same issues as me; the trick is that the `BlueprintNativeEvent` variants magically get some extra methods when creating the events using an interface. Calling these methods should be done using the **Execute\_** method, which gets generated during compilation.

My code for future reference:

**MainCharacterInteraction.h**

```
UINTERFACE(Blueprintable)
class UMainCharacterInteraction : public UInterface
{
	GENERATED_BODY()
};

class MYAPPI_API IMainCharacterInteraction
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Player interaction")
	void Interact();
};

```

**MainCharacterInteraction.cpp**

```
#include "MainCharacterInteraction.h"

```

**MainCharacterInteractionActor.h**

```
UCLASS()
class MYAPI_API AMainCharacterInteractionActor : public AActor, public IMainCharacterInteraction
{
    GENERATED_BODY()

public:
    AMainCharacterInteractionActor(const FObjectInitializer& ObjectInitializer);

    UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category="Player interaction")
    void Interact();
    virtual void Interact_Implementation() override;
};

```

**MainCharacterInteractionActor.cpp**

```
AMainCharacterInteractionActor::AMainCharacterInteractionActor(const FObjectInitializer& ObjectInitializer)
{
}

void AMainCharacterInteractionActor::Interact_Implementation()
{
    // Either called via ObjectThatImplementsInterface->ExecuteInteract(Caller); or using a Blueprint override.
}
```
