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. 

How to pass arg. to a function as an instance of interface type?

I'm trying to pass an pawn of class (AMyPawn), inherited also from an interface (IMyInterface, which have specific method called InterfaceFunction()) to an actor-component method in this way:

 //! MyPawn.h
 class AMyPawn : public APawn, public IMyInterface
 //! UMyComponent.cpp
 void UMyComponent::Func(TScriptInterface<IMyInterface> argumentActor)
     * get argument actor as ptr to IMyInterface 
     * instance and call specific interfce method:
 //! place of calling in some cpp:
 void SomeClass::SomeMethod(AMyPawn* myPawn)

But with this code I get compile-error:

 >C:\MyProject\dev\Engine\Source\Runtime\CoreUObject\Public\UObject\ScriptInterface.h(144): error C2664: 'void FScriptInterface::SetObject(UObject *)' : cannot convert argument 1 from 'IMyInterface *' to 'UObject *'
  >Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Product Version: UE 4.9
more ▼

asked Nov 17 '15 at 11:25 AM in C++ Programming

avatar image

93 15 23 23

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

1 answer: sort voted first

I ran into a similar issue and it turned out I hadn't implemented the declarations of the functions in the interface header properly. I didn't need any BP exposed functionality on my interface. To have a native c++ interface function that you don't need in BP you need to declare your interface function as pure virtual. For example:

 class IInterfaceName
 virtual float InterfaceFunction() const PURE_VIRTUAL(IInterfaceName::InterfaceFunction, return 1.f;);

Then you still need the UInterface wrapper for it as well. Not sure if this is the same problem you were experiencing but I ran into this thread on my way to solving it so figured I would leave my solution here either way.

more ▼

answered May 16 '17 at 05:40 PM

avatar image

1 1

(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