x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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:

FindMarionettistInScene

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:


  • ScriptInterface.h(144): error C2664: 'void FScriptInterface::SetObject(UObject )' : cannot convert argument 1 from 'IMarionettistInterface ' to 'UObject ' MarionettistUtilities.h(8) : see reference to function template instantiation 'InterfaceType &TScriptInterface::operator =(UObjectType )' being compiled with...

  • ScriptInterface.h(146): error C2440: 'initializing' : cannot convert from 'UMarionettistInterface ' to 'IMarionettistInterface ' MarionettistUtilities.h(8) : see reference to function template instantiation 'InterfaceType &TScriptInterface::operator =(UObjectType *)' being compiled with...

  • MarionettistUtilities.h(8): error C2664: 'void UMarionettistUtilities::FindMarionettistInScene(TEnumAsByte,bool &,IMarionettistInterface )' : cannot convert argument 3 from 'TScriptInterface' to 'IMarionettistInterface

  • MarionettistUtilities.h(8): error C2664: 'void UMarionettistUtilities::FindMarionettistInScene(TEnumAsByte,bool &,UMarionettistInterface )' : cannot convert argument 3 from 'TScriptInterface' to 'UMarionettistInterface '

  • void FindMarionettistInScene(TEnumAsByte MarionettistName, bool &Error, const IMarionettistInterface &Interface);

    MarionettistUtilities.h(12) : Missing '*' in Expected a pointer type


... 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 MarionettistUtilities.h is GENERATED_UCLASS_BODY(), and line #12 is the above function I'm trying to compile (currently, it's the only one in the class).

So what is the correct way to convert this blueprint into C++?

Product Version: UE 4.8
Tags:
more ▼

asked Sep 18 '15 at 04:24 AM in C++ Programming

avatar image

MichaelWion
250 27 40 50

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

I found that the following definition compiles:

 static void FindMarionettistInScene(TEnumAsByte<EMarionettist> MarionettistName, bool &Error, TScriptInterface<IMarionettistInterface> &Interface);
more ▼

answered Sep 20 '15 at 09:17 AM

avatar image

MichaelWion
250 27 40 50

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hi MichaelWion,

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:

 virtual UObject* IMarionettistInterface::GetObject() { return nullptr; }
 
 class Marionettist : public AActor, public IMarionettistInterface
 {   
     virtual UObject* GetObject() override {return this;}
 }

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.

 UObject* FindMarionettistInScene(TEnumAsByte MarionettistName, bool &Error);

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.

Interfaces

more ▼

answered Sep 18 '15 at 01:13 PM

avatar image

Mateusz.Wiech
66 7 8 19

avatar image MichaelWion Sep 20 '15 at 09:18 AM

Thanks, see my answer to see how I solved it without a workaround

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question