Returning an interface from C++?
In my current project, I'm converting some blueprints into C++. One of these blueprints is able to search through all actors within the current scene, and return the interface for the first valid object which utilizes said interface:
As you can see, returning an interface works just fine in blueprints. In C++, however, I've tried several different ways to return an interface, and can't get any of them to compile. Here's some of the following setups (and their corresponding errors) that I've tried:
... Anyhow, I'm sure you get the idea. I'm a bit stumped how this is actually done.
Oh, and in case you're interested, line #8 of
So what is the correct way to convert this blueprint into C++?
I found that the following definition compiles:
answered Sep 20 '15 at 09:17 AM
Unfortunately I can't se your image but You can do two things to workaround this:
1) You can add method GetObject to You interface and simply return UObject* from it for every class that will implement this interface:
This way You will get UObject* so compiler won't complain.
2) You can return UObject* in the method instead of IMarionettistInterface* so there is no problem with conversion.
You should remember that IInterface is just a pure C++ class so it's not convertible to UObject* in any way.
Here is a link to the documentation where You can check what are benefits of using UInterfaces.
answered Sep 18 '15 at 01:13 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here