# Referencing Blueprint Interfaces as UPROPERTY

**URL:** <https://forums.unrealengine.com/t/referencing-blueprint-interfaces-as-uproperty/132297>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [October 17, 2019, 8:10pm UTC](https://forums.unrealengine.com/t/referencing-blueprint-interfaces-as-uproperty/132297 "2019-10-17T20:10:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cygon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cygon](https://forums.unrealengine.com/u/cygon)\
**Post date:** [October 17, 2019, 8:10pm UTC](https://forums.unrealengine.com/t/referencing-blueprint-interfaces-as-uproperty/132297/1 "2019-10-17T20:10:56Z")

</div>

I have created a Blueprint interface in C++, like this:

```auto

/// Implemented by dialogs and menus that can be controlled with keyboard and gamepad
class NUCLEX_API IButtonControllableDialog {

  GENERATED_BODY()

  /// Accepts the currently selected dialog option
  public: UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category="UI")
  void Accept();

  /// Cancels the currently selected dialog
  public: UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category="UI")
  void Cancel();

  // ...

};

```

And inherited said interface in a pure Blueprint class:

![inheritinblueprint.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/b/db6b8e354b48edaafa1c75d3e73eb6a3ae9e5c2a.png)

Now I thought my C++ player controller could be given a property like this:

```auto

/// Dialog to which input is currently being sent (can be null if no dialog is active)
public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, Category="UI")
TScriptInterface<IButtonControllableDialog> ActiveDialog;

```

But as I found in the [Interfaces in C++ wiki article](https://wiki.unrealengine.com/Interfaces_in_C%2B%2B#Determining_If_a_Given_Actor_Has_The_Interface), that does not work for Blueprint interfaces implemented in Blueprint. Instead, I have to check:

```auto

this->ActiveDialog->GetClass()->ImplementsInterface(UButtonControllableDialog::StaticClass())

```

Fine.

But if I assign the [FONT=courier new]ActiveDialog property in Blueprint, even though it compiles fine, it instead assigns [FONT=courier new]NULL.

 ![assigningfromblueprint.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/f/a/fab7c213a3e0e7e88c13373764ab83be3c6f7937.png)

It works if I change the property type to [FONT=courier new]UObject \*, but that would totally remove any type information. Blueprinters could assign literally anything :-/

Funnily, if I create a class with an [FONT=courier new]IButtonControllableDialog property in Blueprint and nativize it, the same [FONT=courier new]TScriptInterface\<IButtonControllableDialog\> property is generated.

**How can I create a property of type [FONT=courier new]IButtonControllableDialog that works for both C++ and Blueprint classes?**

---

<div class="post-metadata">

**Author:** ![cygon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cygon](https://forums.unrealengine.com/u/cygon)\
**Post date:** [October 25, 2019, 10:20pm UTC](https://forums.unrealengine.com/t/referencing-blueprint-interfaces-as-uproperty/132297/2 "2019-10-25T22:20:36Z")

</div>

So this is really the state of things?

Either expose properties as (UObject \*) and lose any indication as to which interface type is supposed to be assigned to them,

or expose properties as (UMyBlueprintInterface \*) and lose the ability to ever implement the interface using Blueprints?

☹

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [October 26, 2019, 7:07am UTC](https://forums.unrealengine.com/t/referencing-blueprint-interfaces-as-uproperty/132297/3 "2019-10-26T07:07:41Z")

</div>

Interface implemented to Blueprints using the Editor is an UInterface sub object attached to the Blueprint.  
Casting will never work like that, this is why you get null.

Also there’s no reason to cast anything to call interface methods from Blueprint and Interfaces cannot have properties so I have no idea why you even want to cast them.

---

<div class="post-metadata">

**Author:** ![cygon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cygon](https://forums.unrealengine.com/u/cygon)\
**Post date:** [October 26, 2019, 10:16am UTC](https://forums.unrealengine.com/t/referencing-blueprint-interfaces-as-uproperty/132297/4 "2019-10-26T10:16:41Z")

</div>

Please read my original post.

A) I have a C++ class (let’s say, a custom PlayerController) that has a UPROPERTY:

> [@](#):
>
> Now I thought my C++ player controller could be given a property like this:
> 
> ```auto
> 
> /// Dialog to which input is currently being sent (can be null if no dialog is active)
> public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, Category="UI")
> TScriptInterface<IButtonControllableDialog> ActiveDialog;
> 
> ```

I am not trying to add a UPROPERTY to a blueprint interface.

---

<div class="post-metadata">

**Author:** ![cygon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cygon](https://forums.unrealengine.com/u/cygon)\
**Post date:** [October 26, 2019, 10:23am UTC](https://forums.unrealengine.com/t/referencing-blueprint-interfaces-as-uproperty/132297/5 "2019-10-26T10:23:33Z")

</div>

B) I do not want to cast anything and know there is no need to. All blueprint interface calls are by name (and I can see exactly how someone at Epic attempted to design a system for actual method calls in UE C++, failed and clobbered stuff together to arrive at the current state of things)

I want some semblance of type safety. I’m given two choices in my [FONT=courier new]PlayerController:

**Choice 1:**

```auto

/// Dialog to which input is currently being sent (can be null if no dialog is active)
public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, Category="UI")
TScriptInterface<IButtonControllableDialog> ActiveDialog;

```

The Kismet editor shows the property as being of type [FONT=courier new]IButtonControllableDialog. Nice, the blueprint monkey knows which type to assign to it. Except when he creates a blueprint class and assigns it, it _ **silently fails** _. Yes. it _ **silently fails** _ and assigns null.

**Choice 2:**

```auto

/// Dialog to which input is currently being sent (can be null if no dialog is active)
public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, Category="UI")
UObject *ActiveDialog;

```

The Kismet editor shows an [FONT=courier new]Object pin. The blueprint monkey could assign anything to it and my player controller would eat it. Only when I call [FONT=courier new]IButtonControllableDialog::SomeMethod\_Execute() things would start going wrong.

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [October 26, 2019, 1:26pm UTC](https://forums.unrealengine.com/t/referencing-blueprint-interfaces-as-uproperty/132297/6 "2019-10-26T13:26:31Z")

</div>

UPROPERTY ( EditAnywhere, meta = (AllowedClasses=“ButtonControllableDialog”) )  
UObject \*ActiveDialog;

---

<div class="post-metadata">

**Author:** ![cygon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cygon](https://forums.unrealengine.com/u/cygon)\
**Post date:** [October 26, 2019, 6:30pm UTC](https://forums.unrealengine.com/t/referencing-blueprint-interfaces-as-uproperty/132297/7 "2019-10-26T18:30:50Z")

</div>

Thank you very much!

~~That totally fixes the pain on the Blueprint side for me~~

Erm, correction, it seems to do nothing.

```auto

/// Dialog to which input is currently being sent (can be null if no dialog is active)
public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, Category="UI")
TScriptInterface<IButtonControllableDialog> ActiveDialog;

/// Dialog to which input is currently being sent (can be null if no dialog is active)
public: UPROPERTY(
  EditAnywhere, BlueprintReadWrite, Transient, Category="UI",
  meta = (AllowedClasses = "ButtonControllableDialog")
)
UObject *SameWithBCD;

/// Dialog to which input is currently being sent (can be null if no dialog is active)
public: UPROPERTY(
  EditAnywhere, BlueprintReadWrite, Transient, Category="UI",
  meta = (AllowedClasses = "Gooblefoob")
)
UObject *SameWithGooblefoob;

/// Dialog to which input is currently being sent (can be null if no dialog is active)
public: UPROPERTY(
  EditAnywhere, BlueprintReadWrite, Transient, Category="UI",
  meta = (AllowedClasses = "IButtonControllableDialog")
)
UObject *SameWithIBCD;

/// Dialog to which input is currently being sent (can be null if no dialog is active)
public: UPROPERTY(
  EditAnywhere, BlueprintReadWrite, Transient, Category="UI",
  meta = (AllowedClasses = "UButtonControllableDialog")
)
UObject *SameWithUBCD;

```

 ![variations.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/7/8763f6ef28d8ce3739e0fdd0e2a2b21969132197.png)

According to the docs it should at least affect the asset picker, but that doesn’t seem to happen either.

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

So unless I’m missing something, I’m still at square one.

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [October 26, 2019, 8:38pm UTC](https://forums.unrealengine.com/t/referencing-blueprint-interfaces-as-uproperty/132297/8 "2019-10-26T20:38:47Z")

</div>

Force users to set variable from Details Panel.  
Do not allow BlueprintReadWrite, if it must be set in graph then only a custom Kismet K2Node can do that filtering.

---

<div class="post-metadata">

**Author:** ![RemRemRemRe](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/remremremre/32/974428_2.png) [@RemRemRemRe](https://forums.unrealengine.com/u/RemRemRemRe)\
**Post date:** [July 8, 2021, 4:05pm UTC](https://forums.unrealengine.com/t/referencing-blueprint-interfaces-as-uproperty/132297/9 "2021-07-08T16:05:40Z")

</div>

I am facing the exactly same problem right now.

The interface property related code should be given more love🥺.  
The latest commit of most of the code is from Tim back in 2014🥺.

I seem found the reason in `UObjectBaseUtility::GetInterfaceAddress` : “Native interface should not be implemented by blueprint or you will get `nullptr` because there is no information about the interface address offset in the blueprint class(always 0 currently)”.

And I am curious about

`UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, Category="UI") TScriptInterface<IButtonControllableDialog> ActiveDialog;`

Could `ActiveDialog` be awared by garbage collection system ? Since the `FScriptInterface::ObjectPointer` is naked.
