How to safely store a pointer to my UINTERFACE?

undercover
Fri, 09 May 2014 17:18:49 +0000
UI

Hi!

I have created an UINTERFACE called “MyInterface” i.e. UMyInterface and IMyInterface. A class that implements this interface and inheriting AActor. Then in the world I raycast where the mouse pointer is and get an actor back. I use InterfaceCast to cast it to “IMyInterface” which works good (I can e.g. call my methods). Now I want to store a pointer to my Interface in a way such that I can check something like IsValid because there is no guarantee this actor will live/exist during the whole playthrough.

How is the UE4 interface supposed to be used. If I store the “UMyInterface” I have access to a IsValid method, however then I have no longer access to my methods in “IMyInterface”. How are you supposed to go back and forth between the interfaces. Also how do you get the “UMyInterface” in the first place from e.g. an actor. I have hard to believe that you are supposed to cast the interfaces back and forth between each other instead of using a more type safe approach.

Thanks in advance!

8 posts - 1 participant