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"

Call Blueprint interface implementation for base class from child class

Hello, comrades!

Sorry for my english, but i'll try to explain what i want to do. So, i have inteface in C++:

 #pragma once
 
 #include "Interface.h"
 #include "IPickupItem.generated.h"
 
 UINTERFACE(Blueprintable)
 class MYGAME_API UPickupItem : public UInterface
 {
     GENERATED_BODY()
 };
 
 class MYGAME_API IPickupItem
 {
     GENERATED_BODY()
 
 public: // this methods must be implemented only through Blueprints
     UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "My|InterfaceMethods")
         void PickupItem(USceneComponent* AttachTo); 
 
     UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "My|InterfaceMethods")
         void DropItem();
 };
 

C++ class, which inherits from interface:

 #include "IPickupItem.h" // my interface
     #include "ItemBase.generated.h"
     
     UCLASS()
     class MYGAME_API AItemBase : public AActor, public IPickupItem
     {
     GENERATED_BODY()
 public:
     AItemBase();    .... // (some other stuff, methods, members, etc. don't really matters)
     // BUT! I don't have any overload or overrides of interface methods!
 protected:
 UPROPERTY(Category = "My|Basic", EditAnywhere, BlueprintReadWrite)
         UMeshComponent* itemMesh; // will be inited in child class!
     }

And i have child class of game item, for example:

 #pragma once
 
 #include "CoreMinimal.h"
 #include "ItemBase.h"
 #include "StaticItemBase.generated.h"
 
 UCLASS()
 class MYGAME_API AStaticItemBase : public AItemBase
 {
     GENERATED_BODY()
 public: 
     AStaticItemBase(); // initializes itemMesh from AItemBase with StaticMeshComponent
     UFUNCTION(BlueprintCallable, Category = "My|Methods")
     UStaticMeshComponent* GetStaticMesh(); // returns itemMesh' pointer
 protected:    
 };

Then i'am creating a Blueprint from my AItemBase (ItemBase_BP) class and another one - from AStaticItemBase (StaticItemBase_BP). Some instances of StaticItemBase_BP are placed to game map to interract with. What was my idea: in ItemBase_BP i make implementation of interface methods PickupItem() and DropItem(), that will be called from MotionController BP (standart from VR-sample) using interface call when i'am trying to pick up an object StaticItemBase_BP with motion controller.

All checks like "is overlapping objects implements my interface" are correct and works fine.

Problem is, that execution never comes to ItemBase_BP event PickupItem()/DropItem() for StaticItemBase_BP objects. I think that's because they (objects) are not directly inherited from ItemBase_BP.

ItemBase_BP is inherited from AItemBase C++ class (and C++ interface), StaticItemBase_BP is inherited from AStaticItemBase C++ class (which is inherited from AItemBase C++ class =)).

Please, can someone explain me, how this can be solved? I mean, is there any way to call Blueprint implementation of base class interface function for ALL child objects, which are inherited from that base class?

Thank you! Alex

Product Version: UE 4.19
Tags:
more ▼

asked Jun 06 '18 at 10:50 PM in C++ Programming

avatar image

DarkVoid
1 1

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

0 answers: sort voted first
Be the first one to answer this question
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