# Use of Execute\_Prefix for Interfaces

**URL:** <https://forums.unrealengine.com/t/use-of-execute_prefix-for-interfaces/409437>\
**Category:** UI\
**Tags:** interface, unreal-engine, UE4, question, CPP, calls\
**Created:** [November 12, 2017, 7:29pm UTC](https://forums.unrealengine.com/t/use-of-execute_prefix-for-interfaces/409437 "2017-11-12T19:29:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![neryun](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/neryun/32/722041_2.png) [@neryun](https://forums.unrealengine.com/u/neryun)\
**Post date:** [November 12, 2017, 7:29pm UTC](https://forums.unrealengine.com/t/use-of-execute_prefix-for-interfaces/409437/1 "2017-11-12T19:29:14Z")

</div>

I have a general questions about Interfaces. When reading through the documentation and epics wiki I see that a call to the interface should be by using Execute\_Prefix.

Since I am not getting it to work with Execute\_Prefix I just went head and trialed and errored a bit until i implemented it in this way:

```
IIdentityActorComponentDataInterface* ActorComponentDataInterface = Cast<IIdentityActorComponentDataInterface>(Character);

ActorComponentDataInterface->InitializeActorComponent(Character->DefaultParadigm);

```

Now it works it calls the right interface and I see why but for some reason I feel a bit unsure if I still should try to get it to work wit Execute\_Prefix.

Maybe someone could clarify it.

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [November 12, 2017, 8:05pm UTC](https://forums.unrealengine.com/t/use-of-execute_prefix-for-interfaces/409437/2 "2017-11-12T20:05:43Z")

</div>

You are sure you properly declared interface with UINTERFACE(), UIdentityActorComponentDataInterface class and GENERATED\_BODY() on both I and U class? Considering Execute\_ don’t work and you don’t get assert fail on execution of normal function, means there might be problem in decleration.

Now what you do will indeed work, it still 100% correct in C++ (in fact it is not interface, C++ simply supports multi-parent classes, which can work like interface, UE4 does not support that with UObjects), but you compliantly bypassing enigne management over it, engine don’t see that interface and don’t see being any functions being called. Reason behind Execute\_ function is to make interface work in blueprint, if you gonna directly call interface function in C++ the call won’t be forward up to blueprint system, it will only execute code in C++. So what you doing will work in C++, but won’t work in blueprint, there also potential of some errors by using interface like that, because again what you have is caused by UE4 not adding this interface in reflection system so engine have 0 idea of this interface and functions existence.

Remember that regardless of people calling it “UE4 C++” it is still normal C++ and all C++ code incompatible with UE4 APIs will build and work, but if you not going to be careful with it you will get errors and crashes.

---

<div class="post-metadata">

**Author:** ![neryun](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/neryun/32/722041_2.png) [@neryun](https://forums.unrealengine.com/u/neryun)\
**Post date:** [November 13, 2017, 9:22pm UTC](https://forums.unrealengine.com/t/use-of-execute_prefix-for-interfaces/409437/3 "2017-11-13T21:22:13Z")

</div>

First off thanks a lot for your extensive answer. That makes a lot of sense. And as you said in the last sentence I would like to go the careful route to implement as intended by the UE4 API.

I am very sure I did declare it. Here you go:

```
UINTERFACE(MinimalAPI)
class UIdentityActorComponentDataInterface : public UInterface
{
	GENERATED_BODY()
};

class IIdentityActorComponentDataInterface
{
	GENERATED_BODY()

/ ************************************************************************ /
/* Defaults */
/ ************************************************************************ /
public:
	/**
	* Initializes and loads all data from the Component
	*/
	virtual void InitializeActorComponent(TSubclassOf<UIdentityParadigmComponent> ParadigmComponent);
	virtual void InitializeActorComponent(TSubclassOf<UIdentityWeaponComponent> WeaponComponent);
	virtual void InitializeActorComponent();
};

```

Also I will not use it in Blueprint at all.

---

<div class="post-metadata">

**Author:** ![neryun](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/neryun/32/722041_2.png) [@neryun](https://forums.unrealengine.com/u/neryun)\
**Post date:** [November 13, 2017, 11:07pm UTC](https://forums.unrealengine.com/t/use-of-execute_prefix-for-interfaces/409437/4 "2017-11-13T23:07:16Z")

</div>

Just as a thought.

Is Execute\_Prefix only if I use actually a BlueprintNativeImplementation as it will call than Blueprint but pure C++ calls it as I already done it?

Looking at [Calling Interface Functions In C++ - UI - Unreal Engine Forums](https://answers.unrealengine.com/questions/250263/calling-interface-functions-in-c.html)

---

<div class="post-metadata">

**Author:** ![neryun](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/neryun/32/722041_2.png) [@neryun](https://forums.unrealengine.com/u/neryun)\
**Post date:** [November 14, 2017, 9:32pm UTC](https://forums.unrealengine.com/t/use-of-execute_prefix-for-interfaces/409437/5 "2017-11-14T21:32:42Z")

</div>

Found my answer in [Grand unified C++/blueprint cast interface explanation - UI - Epic Developer Community Forums](https://answers.unrealengine.com/questions/214147/grand-unified-cblueprint-cast-interface-explanatio.html)

> The solution is basically message  
> passing. UE4 uses the  
> GENERATED\_IINTERFACE\_BODY() macro  
> which you call in the IFooInterface  
> definition to add the Execute\_\*  
> methods as static methods of your  
> class. What Execute\_DoSomething does  
> is basically send a message to a  
> UObject and says “Please see if you  
> claim to implement the methods in  
> IFooInterface and if so call the  
> DoSomething method.” This is kind of  
> like how classes work in languages  
> like python or Objective C or  
> Smalltalk but not how classes  
> generally work in C++ (which is why I  
> found everything so confusing).

---

<div class="post-metadata">

**Author:** ![Arty-McLabin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arty-mclabin/32/1012076_2.png) [@Arty-McLabin](https://forums.unrealengine.com/u/Arty-McLabin)\
**Post date:** [March 25, 2018, 7:57pm UTC](https://forums.unrealengine.com/t/use-of-execute_prefix-for-interfaces/409437/6 "2018-03-25T19:57:43Z")

</div>

@anonymous_user_f5a50610,  
I do not quite understand what does it mean to work in C++ but not in BP. Do you mean the C++ version of the function will be always running instead of the BP override if you don’t use Execute\_ ?  
Otherwise can you please give an example where will it not work correctly?

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [November 22, 2018, 1:00am UTC](https://forums.unrealengine.com/t/use-of-execute_prefix-for-interfaces/409437/7 "2018-11-22T01:00:53Z")

</div>

Yes, that because this is cold blood C++ compiled to machine code, if you call function in C++, CPU unconditionally jump to that function code, UE4 don’t have any chance to detect that and intercept that to execute blueprint implementation of interface, or else engine will generate function definition with code calling blueprint function on compile time, which it does not due as it would needlessly complicate use of interface in C++ (but it does that with BlueprintNativeEvent), insted you call generated Execute\_ function which checks if there blueprint implementation and executes it if it is or goes call C++ function if it’s not.

---

<div class="post-metadata">

**Author:** ![Arty-McLabin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arty-mclabin/32/1012076_2.png) [@Arty-McLabin](https://forums.unrealengine.com/u/Arty-McLabin)\
**Post date:** [November 22, 2018, 11:15am UTC](https://forums.unrealengine.com/t/use-of-execute_prefix-for-interfaces/409437/8 "2018-11-22T11:15:44Z")

</div>

makes perfect sense, thanks for the clarification mate :]
