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"

How to call interface function from base class?

Title says its all. I'm struggling with calling implementation of my interface funtion from the base class. Here is an example: I got interface, let's call it ITestInterface

     class MYPROJ_API ITestInterface
     {
         GENERATED_BODY()
     
         // Add interface functions to this class. This is the class that will be inherited to implement this interface.
     public:
         UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
         void MyTestFunction();
 }

and I got class that implements this interface

 UCLASS()
 class MYPROJ_API ABaseTestActor : public AActor, public  ITestInterface
 {
     GENERATED_BODY()
     
 public:    
     ATestActor();
 
     virtual void MyTestFunction_Implementation() override;
 };

and than I got derived class.

 UCLASS()
 class MYPROJ_API ADerrivedTestActor : public  ABaseTestActor
 {
     GENERATED_BODY()
 public:
     ADerrivedTestActor ();
         
         virtual void MyTestFunction_Implementation() override;
 }

Inside of the DerrivedTestActor::MyTestFunction_Implementation() I want to do something like Super::MyTestFunction() but since it's and interface I have to use proper Execute_ call and pass the pointer to the object on which the function should be called. I 've tried Super::Execute_MyTestFunction(this) and it compiles but I got "Fatal Error" during the runtime.

I've also tried something like this

 Super* thisSuper = Cast<Super>(this);
 thisSuper->Execute_HandleGrab(thisSuper)

but it also throws Fatal Error during runtime.

Does anyone know how to call such a function? thanks in advance.

Product Version: UE 4.19
Tags:
more ▼

asked Nov 19 '18 at 12:51 PM in C++ Programming

avatar image

S_Q_R
23 2 6 7

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

1 answer: sort voted first

Hello,

It should be as simple as doing this:

 // DerrivedTestActor.cpp
 
 void ADerrivedTestActor::MyTestFunction_Implementation()
 {
     Super::MyTestFunction_Implementation();
 }

You should not need to call the interface Execute_, just the implementation function. The Execute_ function should only be used from other classes to avoid casting to specific types.

~ Dennis "MazyModz" Andersson

more ▼

answered Nov 19 '18 at 03:16 PM

avatar image

MazyModz
266 4 5 6

(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