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"

Executing overridden blueprint interface functions from C++?

I am having a problem trying to call a method on an interface from c++ to invoke and overridden function in a blueprint class.

  • Define interface in C++; IHelp with one method named bool Test()

  • Define actor in C++; Foo that inherits IHelp

  • Derive blueprint actor from Foo; Boo

  • Override bool Test() as a function in Boo

  • I add Boo to the level and then call a function Library method which invokes IHelp -> Test() on Boo. the function library is written in C++.

  • Boo does implement the interface without any problem executes But … the overridden function never gets called?

I have tried everything with no success. I think this post describe the problem I'm having, but I have tried all of the tips and it still does not work. https://answers.unrealengine.com/questions/214147/grand-unified-cblueprint-cast-interface-explanatio.html?fbclid=IwAR0z0t4QkmUTywZajmefGToY1HoHYfqtt5LWqZNQtE5Xl2mkasocV95971U

Any advice would be appreciated!

Product Version: UE 4.22
Tags:
more ▼

asked Jul 11 '19 at 10:15 PM in C++ Programming

avatar image

HT Aidn
206 3 10 36

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

2 answers: sort voted first

You need to call your function with Execute_ prefix which will call blueprint if function id overrided so Execute_Test(). It's a function generated by UHT.

more ▼

answered Jul 12 '19 at 02:23 AM

avatar image

Shadowriver
37.2k 936 172 1116

avatar image HT Aidn 4 days ago

Hi Shadow, I was doing that. I'm going to redo the class do a simple test example and try it again. I will post the code and results. much appreciated you hanging in there and trying to help me. :-)

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

It works! I honestly think I must be losing my mind because I tried this so many times doing the exact same thing and it never worked before. For the sake of being complete and documenting the solution for others who may be struggling here is my code . thanks again shadow!

lockable.h

 // This class does not need to be modified.
 UINTERFACE(MinimalAPI)
 class ULockable : public UInterface
 {
     GENERATED_BODY()
 };
 
 /**
  * 
  */
 class EMBER_API ILockable
 {
     GENERATED_BODY()
 
     // Add interface functions to this class. This is the class that will be inherited to implement this interface.
 public:
     UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Lockable")
         void Lock(const FString &key);
 };

lockingactor.h

 UCLASS()
 class EMBER_API ALockingActor : public AActor, public ILockable
 {
     GENERATED_BODY()
     
 public:    
     // Sets default values for this actor's properties
     ALockingActor();
 
 protected:
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
 
 public:    
     // Called every frame
     virtual void Tick(float DeltaTime) override;
     
     UPROPERTY(EditAnywhere, BlueprintReadWrite)
         FString key = FString();
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite)
         bool isLocked = false;
 
 
 };

test lock

 void UFunctionLibrary::TestLock(AActor * actor)
 {
     if (actor->GetClass()->ImplementsInterface(ULockable::StaticClass()))
     {
         FGuid guid = FGuid::NewGuid();
         ILockable::Execute_Lock(actor, guid.ToString());
     }
 }

Create a blueprint based on locking actor, and then implement the Event Lock. When you call the Execute_Lock function in your C++ Code the blueprint event will be called.

Good luck!

more ▼

answered Jul 12 '19 at 02:11 PM

avatar image

HT Aidn
206 3 10 36

(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