# InerfaceCast returns null for blueprint classes implementing that interface

**URL:** <https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213>\
**Category:** Feedback & Requests\
**Tags:** unreal-engine, documentation, CPP, Blueprint, question\
**Created:** [May 13, 2014, 8:58am UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213 "2014-05-13T08:58:01Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [May 13, 2014, 8:58am UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/1 "2014-05-13T08:58:01Z")

</div>

Branch 4.1 tag 4.1.1  
I don’t know if it is an intended feature or a bug, but you cannot use InterfaceCast to expose class interfaces that are set in blueprint.  
The code below is demonstrated a solution:

```
//Interface
#pragma once
#include "KinectFunctionLibrary.h"
#include "KinectListenerInterface.generated.h"

UINTERFACE(Blueprintable)
class UKinectListenerInterface : public UInterface
{
	GENERATED_UINTERFACE_BODY()
};

class IKinectListenerInterface
{
	GENERATED_IINTERFACE_BODY()

public:

	UFUNCTION(BlueprintImplementableEvent, Category = NUI)
		void ReciveBody(const FBodyFrame& BodyFrame);
};

//Event Dispatcher

void KinectEventDispatcher::DispatchEvent(){

	FBodyFrame Frame = KinectSensor::Get().GetBodyFrame();

	for (TObjectIterator<AActor> It; It; ++It) //Iterate over all actors
	{
		IKinectListenerInterface* ListenerInterface = NULL;

		//Try InterFaceCasting
		IKinectListenerInterface = InterfaceCast<IKinectListenerInterface>(*It);

		//Problem/Bug/Feature? ListenerInterface is null, Event is not triggered
		if (ListenerInterface)
			ListenerInterface->Execute_ReciveBody(Frame);
    
            //Solution: Triggers the event 
		if ((*It)->GetClass()->ImplementsInterface(UKinectListenerInterface::StaticClass())){

			IKinectListenerInterface::Execute_ReciveBody((*It), Frame);

		}

	}

}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b666e59e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b666e59e](https://forums.unrealengine.com/u/anonymous_user_b666e59e)\
**Post date:** [May 13, 2014, 5:23pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/2 "2014-05-13T17:23:21Z")

</div>

Hi . I am little unsure about exactly what you are trying to do in a couple lines of your code sample. In line 36, it looks like you are creating a pointer named `ListenerInterface`, and setting the value to `NULL`. Then, in line 42, you are checking the see if `ListenerInterface` contains a valid value, which it does not since it is still `NULL`, so the following line never triggers.

Is your InterfaceCast in line 39 supposed to be updating the value stored in `ListenerInterface`? If you can clarify what those lines are trying to do, I can look into this a bit more for you.

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [May 13, 2014, 5:41pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/3 "2014-05-13T17:41:41Z")

</div>

Sorry if I was unclear, in my code lines 36 to 43 are commented out and they are the reason I reported this bug.  
Lines 46 to 50 are the solution to the problem I had in lines 36 to 43.  
This snippet is the event dispatcher part of my Kinect plugin.  
The goal of this code is to make my plugin native code “free” so everyone could use it without the need to see native code.  
To achieve that I created an Interface IKinectListenerInterface which can be implemented inside the editor by any class that the user wants to receive events from the Kinect.  
While exposing native interfaces to blueprints is pretty much straight forward the other way using InterfaceCast method described here:

> **[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...

on an Blueprint generated class returns null.  
I hope that explains my report better.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b666e59e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b666e59e](https://forums.unrealengine.com/u/anonymous_user_b666e59e)\
**Post date:** [May 13, 2014, 6:08pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/4 "2014-05-13T18:08:28Z")

</div>

Thank you for the clarification. I will continue looking into this for you. I am still a little unsure where `ListenerInterface` is being set to a value other than `NULL`, but I think I have what I need to investigate this.

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [May 13, 2014, 6:12pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/5 "2014-05-13T18:12:11Z")

</div>

I set it to null to avoid access violation in case that it initialized to garbage value

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b666e59e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b666e59e](https://forums.unrealengine.com/u/anonymous_user_b666e59e)\
**Post date:** [May 13, 2014, 6:52pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/6 "2014-05-13T18:52:03Z")

</div>

I saw where you had declared the pointer and set it to `NULL`. I was just unsure where the pointer’s value was being changed to something else so the `if` check would work. I have reached out to one of our developers for some insight into this issue. I hope to receive some feedback from him within a few days.

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [May 13, 2014, 6:58pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/7 "2014-05-13T18:58:29Z")

</div>

Thanks!  
I found a workaround (lines 46 to 50) so personally this bug doesn’t bother me anymore, hope my workaround could assist you.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 13, 2014, 7:34pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/8 "2014-05-13T19:34:10Z")

</div>

that’s a nifty solution, thanks for sharing Lion!

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [May 13, 2014, 7:37pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/9 "2014-05-13T19:37:24Z")

</div>

No! Thank you !  
I’m reading one of your tutorials as we speak 😃  
(And I kinda need your help with something about it :P)

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 13, 2014, 7:45pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/10 "2014-05-13T19:45:27Z")

</div>

hee hee!

well you did great research yourself, so congrats!

you can pm me about your issue (so this thread stays focused)

---

<div class="post-metadata">

**Author:** ![Nick\_Whiting](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nick\_Whiting](https://forums.unrealengine.com/u/Nick_Whiting)\
**Post date:** [May 22, 2014, 4:40pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/11 "2014-05-22T16:40:54Z")

</div>

If you’re using a BP interface, you need to use ScriptInterfaceCast instead of an InterfaceCast. You can check out the difference in Casts.h, where the two functions are defined.

The root of the problem with using the InterfaceCast is that it’s looking for a native entry point for the interface. But, since it’s implemented in BP, there is no native entry point, and you need to use the ScriptInterfaceCast to properly set things up.

However, the best way to use interfaces is with the IMyInterface::Execute\_MyFunction, because that handles both the native and BP cases via the same path.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [May 22, 2014, 4:46pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/12 "2014-05-22T16:46:27Z")

</div>

Thanks!  
But if you’ll look at lines 46-50 in the code in the original post I have already proposed a solution in the bug report using IMyInterface::Execute\_MyFunction, I reported the bug after finding that workaround 🙂

---

<div class="post-metadata">

**Author:** ![Nick\_Whiting](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nick\_Whiting](https://forums.unrealengine.com/u/Nick_Whiting)\
**Post date:** [May 22, 2014, 6:19pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/13 "2014-05-22T18:19:56Z")

</div>

Yup, saw those, but figured people might be interested in the “why” as well. Glad you’re up and rolling!

---

<div class="post-metadata">

**Author:** ![ChrisJD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ChrisJD](https://forums.unrealengine.com/u/ChrisJD)\
**Post date:** [July 14, 2014, 11:12pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/14 "2014-07-14T23:12:44Z")

</div>

+1 for the “Why” explanation. I was looking at the Strategy example and wondering if there was a reason to prefer the IMyInterface::Execute\_MyFunction approach over an InterfaceCast and now I know there is and why. The why is pretty important for really understanding something.

---

<div class="post-metadata">

**Author:** ![Xarol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xarol](https://forums.unrealengine.com/u/Xarol)\
**Post date:** [April 18, 2015, 6:56pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/15 "2015-04-18T18:56:20Z")

</div>

I just wanted to say I found this question really helpful in getting my interface stuff to work.

I wrote up a more detailed summary of what is going on and why at [Grand unified C++/blueprint cast interface explanation - UI - Unreal Engine Forums](https://answers.unrealengine.com/questions/214147/grand-unified-cblueprint-cast-interface-explanatio.html)  
in case others have similar issues or in case you were wondering why this is so complicated. 🙂

---

<div class="post-metadata">

**Author:** ![Froggy\_C](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Froggy\_C](https://forums.unrealengine.com/u/Froggy_C)\
**Post date:** [April 27, 2016, 3:46pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/16 "2016-04-27T15:46:57Z")

</div>

This is literally the _only place on the internet_ where I’ve found this `ScriptInterfaceCast` function mentioned. It certainly isn’t in my `Casts.h` file.

Was it removed from the codebase?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b666e59e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b666e59e](https://forums.unrealengine.com/u/anonymous_user_b666e59e)\
**Post date:** [May 3, 2016, 1:35pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/17 "2016-05-03T13:35:56Z")

</div>

Hi ,

Casts were overhauled in version 4.6 to simplify their use. Part of that change was the removal of `ScriptInterfaceCast()`. From the version 4.6 release notes:

> **Simplified Casting**
> 
> - Easily cast between Unreal classes using the improved Cast() function. You can even cast between interfaces and classes. We also now support using dynamic\_cast to cast between Unreal types, if you prefer that.

If you are having some trouble with casting, please submit a new question since casting has changed significantly from when this question was originally asked.

---

<div class="post-metadata">

**Author:** ![Rumbleball](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rumbleball](https://forums.unrealengine.com/u/Rumbleball)\
**Post date:** [November 7, 2016, 4:59pm UTC](https://forums.unrealengine.com/t/inerfacecast-returns-null-for-blueprint-classes-implementing-that-interface/283213/18 "2016-11-07T16:59:32Z")

</div>

Just for completion.  
What was looking for is line 39.

```
//Wrong
IKinectListenerInterface = InterfaceCast<IKinectListenerInterface>(*It);

//Right
ListenerInterface = InterfaceCast<IKinectListenerInterface>(*It);

```

Without that change the If check in Line 42 will not work because ListenerInterface is never changed and will be NULL.
