# 5.1 // Calling C++ interface function does not execute BP event implementation

**URL:** <https://forums.unrealengine.com/t/5-1-calling-c-interface-function-does-not-execute-bp-event-implementation/732403>\
**Category:** Programming & Scripting\
**Tags:** interface, UE-5, unreal-engine, Blueprint, CPP, question\
**Created:** [December 20, 2022, 10:03am UTC](https://forums.unrealengine.com/t/5-1-calling-c-interface-function-does-not-execute-bp-event-implementation/732403 "2022-12-20T10:03:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebuch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ebuch/32/1071060_2.png) [@ebuch](https://forums.unrealengine.com/u/ebuch)\
**Post date:** [December 20, 2022, 10:03am UTC](https://forums.unrealengine.com/t/5-1-calling-c-interface-function-does-not-execute-bp-event-implementation/732403/1 "2022-12-20T10:03:40Z")

</div>

Hi everyone,

I am relatively new to C++ and working to move certain functionalities out of blueprints. Any help or pointers in the right direction would be highly appreciated! ✨

**To start, here are my classes:**

```auto
UCelestialSkySubsystem // inherits from UEngineSubsystem
UCelestialSkyInterface & ICelestialSkyInterface // cpp interface
ACelestialActorBase // cpp class inheriting from AActor and ICelestialSkyInterface
BP_CelestialBody // abstract BP class inheriting from ACelestialActorBase
BP_Planet // inherits from BP_CelestialBody and implements interface events

```

I have a function in my subsystem that updates a number, then calls an implemented interface event on each actor in an array of _ACelestialActorBase_ actors—I know these are _BP\_Planet_ actors spawned into the world.

**The problem is that calling the _Execute\_Prefix_ function in my subsystem does not call the implemented event in my _BP\_Planet_ actors.**

Based on findings in this thread ([C++ Interface implemented in BP is null](https://forums.unrealengine.com/t/c-interface-implemented-in-bp-is-null/491758)) and the others linked inside it, I know that my BP actors must inherit the interface from a cpp class. I think I have done this properly (see my classes above)—everything compiles, no errors, no crashes, but simply nothing happens when calling _Execute\_OnElapsedTimeChanged_.

I do not have C++ implementations for the interface methods.

The subsystem’s function is _SetElapsedTime_ and the interface method is _OnElapsedTimeChanged_.

> **CelestialSkySubsystem.cpp (click to show)**
>
> ```auto
> void UCelestialSkySubsystem::SetElapsedTime()
> {
> // [...set ElapsedTime code...]
> 
> // Make an array of values from TMap CelestialBodyActorReferences.
> TArray<ACelestialActorBase*> CelestialActors;
> CelestialBodyActorReferences.GenerateValueArray(CelestialActors);
> 
> // For each CelestialActor, call the OnElapsedTimeChanged interface function.
> for (ACelestialActorBase* CelestialActor : CelestialActors)
> {
> bool bImpl = UKismetSystemLibrary::DoesImplementInterface(CelestialActor, UCelestialSkyInterface::StaticClass());
> if (bImpl) // this returns true.
> {
> ICelestialSkyInterface::Execute_OnElapsedTimeChanged(CelestialActor); // this is the part where nothing happens.
> }
> }
> }
> 
> ```

> **CelestialSkyInterface.h (click to show)**
>
> ```auto
> #pragma once
> 
> #include "CoreMinimal.h"
> #include "CelestialSkyInterface.generated.h"
> 
> UINTERFACE()
> class UCelestialSkyInterface : public UInterface
> {
> GENERATED_BODY()
> };
> 
> class CELESTIALSKY_API ICelestialSkyInterface
> {
> public:
> GENERATED_BODY()
> 
> UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "CelestialSky|Time")
> void OnElapsedTimeChanged();
> }
> 
> ```

**BP\_Planet implementation:**

![OnElapsedTimeChanged](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/2/e/d2e64ed5c2e2cc43ef7fd67751ed7dcf8c291efb.png)

The _PrintString_ does not do anything when _Execute\_OnElapsedTimeChanged_ is called.

**Here is the BP equivalent of what I’m trying to achieve in C++:**

 ![OnElapsedTimeChangedBP](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/6/0/7607c7bb12759334d7f6eaeae48f6ff6664ad0b7.png)

This BP equivalent works flawlessly when being used in my editor utility widget, but I am having a great deal of trouble getting this over to C++.

Please help! Thanks again!

---

<div class="post-metadata">

**Author:** ![ebuch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ebuch/32/1071060_2.png) [@ebuch](https://forums.unrealengine.com/u/ebuch)\
**Post date:** [December 21, 2022, 11:43pm UTC](https://forums.unrealengine.com/t/5-1-calling-c-interface-function-does-not-execute-bp-event-implementation/732403/2 "2022-12-21T23:43:32Z")

</div>

My best and only guess is that it has to do with my EngineSubsystem possibly(?) existing on a separate background thread from the game thread. I’m going to try to work around this by having two separate subsystems—one for use in the editor and one for use at runtime. My plugin already has two separate modules for this purpose so it should work out.

---

<div class="post-metadata">

**Author:** ![AdamGillJawLtd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AdamGillJawLtd](https://forums.unrealengine.com/u/AdamGillJawLtd)\
**Post date:** [June 7, 2023, 8:46am UTC](https://forums.unrealengine.com/t/5-1-calling-c-interface-function-does-not-execute-bp-event-implementation/732403/3 "2023-06-07T08:46:08Z")

</div>

Hey ebuch, I was just facing this issue as well (I was here looking for answers haha). I don’t have an Editor part like you do but I just fixed my issue by having the C++ class inherit from the interface class directly in C++ instead of adding it to the BP. I’m not sure that applies to you but definitely try it out if you’ve still not solved this.

---

<div class="post-metadata">

**Author:** ![ebuch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ebuch/32/1071060_2.png) [@ebuch](https://forums.unrealengine.com/u/ebuch)\
**Post date:** [June 7, 2023, 7:03pm UTC](https://forums.unrealengine.com/t/5-1-calling-c-interface-function-does-not-execute-bp-event-implementation/732403/4 "2023-06-07T19:03:40Z")

</div>

Hey thanks for the reply! I did get my implementation working a while back—here’s my current setup, in the hopes that it will assist someone else in the future:

I have an engine subsystem that keeps track of a time clock. When my actors are spawned, they subscribe to the subsystem and then receive an interface function call every time the time changes.

> **Interface header file**
>
> ```auto
> UINTERFACE()
> class UCelestialTimeInterface : public UInterface
> {
> GENERATED_BODY()
> };
> 
> class CELESTIALSKY_API ICelestialTimeInterface
> {
> 
> GENERATED_BODY()
> 	
> public:
> UFUNCTION(BlueprintNativeEvent)
> void OnCurrentTimestampChanged(double CurrentTimestamp);
> virtual void OnCurrentTimestampChanged_Implementation(double CurrentTimestamp) {}
> };
> 
> ```

> **Subscribe & Unsubscribe functions**
>
> ```auto
> void UCelestialTimeSubsystem::SubscribeToTimeChanges(UObject* Subscriber)
> {
> if (Subscriber && Subscriber->GetClass()->ImplementsInterface(UCelestialTimeInterface::StaticClass()))
> {
> SubscribedObjects.AddUnique(Subscriber);
> }
> }
> 
> void UCelestialTimeSubsystem::UnsubscribeFromTimeChanges(UObject* ObjectToUnsubscribe)
> {
> SubscribedObjects.RemoveSingleSwap(TWeakObjectPtr<UObject>(ObjectToUnsubscribe));
> }
> 
> ```

> **Notify subscribers function**
>
> ```auto
> void UCelestialTimeSubsystem::NotifyCurrentTimestampChanged(const double NewTimestamp)
> {
> for (TWeakObjectPtr<UObject>& Subscriber : SubscribedObjects)
> {
> if (!Subscriber.IsValid())
> {
> continue;
> }
> if (Subscriber->GetClass()->ImplementsInterface(UCelestialTimeInterface::StaticClass()))
> {
> ICelestialTimeInterface::Execute_OnCurrentTimestampChanged(Subscriber.Get(), NewTimestamp);
> }
> if (ICelestialTimeInterface* CelestialTimeInterface = Cast<ICelestialTimeInterface>(Subscriber))
> {
> CelestialTimeInterface->OnCurrentTimestampChanged_Implementation(NewTimestamp);
> }
> }
> }
> 
> ```

Execute\_OnCurrentTimestampChanged() calls Blueprint implementations.  
OnCurrentTimestampChanged\_Implementation() calls C++ implementations.

This works regardless of whether the interface was inherited in C++ or implemented directly into a Blueprint (I’m using an editor utility widget).
