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"

Can Unreal C++ Interfaces inherit from other Unreal C++ Interfaces?

Hi, I am testing how much I can stretch the engine. I would like to create this kind of interface structure in Unreal 4:

alt text

Is it possible to make an interface inherit another interface? According to this thread yes but I did not manage to make it compile.

If it is not possible how would you go about creating this type of inheritance tree?

Thanks!

Product Version: UE 4.7
Tags:
interfaces.png (2.5 kB)
more ▼

asked May 28 '15 at 02:59 PM in C++ Programming

avatar image

Strauzen
70 9 10 18

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

1 answer: sort voted first

So I just tried this with 4.12.

I was able to have an Interface like so in C++...

UMyInterface2 : UMyInterface 1 {...}

//with an event in the parent and an event in the child.

...and that would compile, but if you go into the editor and create any blueprints (using BlueprintNativeEvent), and add the child interface, any time you try to compile that blueprint with the child event placed in the event graph, it will say that there is a node of the same name that exists already and won't compile. This does NOT happen so long as you don't try to actually create the child event and only reference the events that are native to the child. If you remove the child and add the parent interface, then it can compile with the parent event without issue.

I haven't tried it yet with regular functions or in C++ yet. I suspect functions in BP would work the same way and not compile, but perhaps the C++ side won't complain?

more ▼

answered Jun 16 '16 at 10:41 PM

avatar image

Envisioner
189 10 17 24

avatar image Envisioner Jun 17 '16 at 08:07 PM

Just confirmed that the C++ side can see the _Implementation version of BlueprintNativeEvent-type inherited interface functions in a test actor that implements the child interface. The UE_LOG in ATestActor::OnAdd_Implementation successfully logs when called from its BeginPlay method.

 UINTERFACE(NotBlueprintable)
 class SPECTRAL_API UStorageComponentIntf : public UInterface
 {
     GENERATED_UINTERFACE_BODY()
 };
 
 class SPECTRAL_API IStorageComponentIntf {
 
     GENERATED_IINTERFACE_BODY()
 
 public:
 
     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "StorageComponentIntf")
     void OnAdd();
 
     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "StorageComponentIntf")
     void OnRemove();
 
 };
 
 -----
 
 UINTERFACE(NotBlueprintable)
 class SPECTRAL_API UCompositeStorageIntf : public UStorageComponentIntf
 {
     GENERATED_UINTERFACE_BODY()
 };
 
 class SPECTRAL_API ICompositeStorageIntf {
 
     GENERATED_IINTERFACE_BODY()
 
 public:
 
     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "CompositeStorageIntf")
     EStorageName GetName();
 };
 
 ----
 
 UCLASS()
 class SPECTRAL_API ATestActor : public AActor, public ICompositeStorageIntf
 {
     GENERATED_BODY()
     
 public:    
     // Sets default values for this actor's properties
     ATestActor();
 
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
     
     // Called every frame
     virtual void Tick( float DeltaSeconds ) override;
 
     EStorageName GetName_Implementation();
 
     void OnAdd_Implementation();
 };
 
 ---
 
 EStorageName ATestActor::GetName_Implementation() {
     return EStorageName::SN_Skills;
 }
 
 void ATestActor::OnAdd_Implementation() {
     UE_LOG(LogTemp, Warning, TEXT("OnAdd_Implementation has triggered"));
     return;
 }
 
avatar image Envisioner Jun 17 '16 at 08:10 PM

Based on the fact that Blueprints may have trouble with this though, it may be that you will need to make every interface that is part of an interface inheritance hierarchy NonBlueprintable. You'd also likely need to prevent any blueprint objects from implementing those interfaces to avoid name collisions as detailed in my initial answer.

(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