# How to have interface type as UPROPERTY?

**URL:** <https://forums.unrealengine.com/t/how-to-have-interface-type-as-uproperty/315890>\
**Category:** UI\
**Tags:** interface, unreal-engine, CPP, question\
**Created:** [April 22, 2015, 1:09am UTC](https://forums.unrealengine.com/t/how-to-have-interface-type-as-uproperty/315890 "2015-04-22T01:09:38Z")\
**Posts on this page:** 3\
**Page:** 1

<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 22, 2015, 1:09am UTC](https://forums.unrealengine.com/t/how-to-have-interface-type-as-uproperty/315890/1 "2015-04-22T01:09:38Z")

</div>

How do I use an interface type as a UPROPERTY in c++? For example, in Blueprint the function GetAllActorsWithInterface takes an interface type as an argument. How could I make a C++ class which had a UFUNCTION like this or a UPROPERTY like this?

Thanks,  
-X

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_957a4452](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_957a4452](https://forums.unrealengine.com/u/anonymous_user_957a4452)\
**Post date:** [April 23, 2015, 7:33am UTC](https://forums.unrealengine.com/t/how-to-have-interface-type-as-uproperty/315890/2 "2015-04-23T07:33:01Z")

</div>

Hello, Xarol

In order to implement the desired functionality, consider using TScriptInterface smart pointer. The declaration will look something like this:

```
UPROPERTY()
TScriptInterface<IUsableInterface> InterfacePointer;

```

The reason smart pointer is needed is that garbage collector is not interface-aware. Please note, that you need to assign it via the UObject type instead of the interface type. Also, nulling this pointer requires an explicit cast:

```
InterfacePointer = (IUsableInterface*)nullptr;

```

Hope that helps!

---

<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 23, 2015, 12:49pm UTC](https://forums.unrealengine.com/t/how-to-have-interface-type-as-uproperty/315890/3 "2015-04-23T12:49:13Z")

</div>

Thanks for the reply.

I think what you are saying is that if I want a property which can be an instance of an object which implements IUsableInterface then I can use TScriptInterface. Is that right?

What I actually want is to be able to pass an interface class like GetAllActorsOfInterface.

For example, I want to be able to do something like

UPROPERTY  
UClass\* DesiredInterfaceType;

and then be able to do something in C++ to all actors which implement that interface.

Maybe the clearest way to say it is as follows: “How would I implement GetAllActorsOfInterface in C++ so that the interface was specified in blueprint but the function was implemented in C++?”

Thanks
