Safely Casting An AActor* to IMyInterface* ?
I have the following interface declarations and some function that tries to cast an actor to my interface. Is this an acceptable way to cast to an interface with the Unreal framework?
Good news! It's much easier than that. You just have to try casting your object to the interface class. If the cast succeeds, that object implements the interface, and you can call your interface functions as desired. If the cast fails, the object does not implement the interface.
So your code might look something like:
If you're not familiar with it, check out this wiki page about Interfaces in C++, which explains and shows how to properly use them. Note that the correct way to call interface functions is to use the Execute_ prefix (this is explained further in the wiki page).
answered Jan 17 '19 at 09:23 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here