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"

Implementing a UInterface in a UStruct c++

Hello,

I have just started learning Unreal and am trying to create a USTRUCT that implements a UINTERFACE

I have an Item struct:

 USTRUCT(BlueprintType)
 struct FAMINE_API FItem : public IInteractableInterface
 {
     GENERATED_BODY()
 
 public:
     UFUNCTION(BlueprintNativeEvent)
     virtual void Interact(class AActor* InteractingActor) override;
 
 private:
     UPROPERTY(EditAnywhere, meta = (AllowPrivateAccess = "true"))
     class UItemDataAsset* ItemData;
 };

and an Interactable UINTERFACE

 UINTERFACE(MinimalAPI)
 class UInteractableInterface : public UInterface
 {
     GENERATED_BODY()
 
 };
 
 /**
  * 
  */
 class FAMINE_API IInteractableInterface
 {
     GENERATED_BODY()
 
     // Add interface functions to this class. This is the class that will be inherited to implement this interface.
 public:
     virtual void Interact(class AActor* InteractingActor) = 0;
     
 };
 

The problem is that the header tool expects the struct to inherit from another UStruct and then throws the following error at compile time:

Parent Struct 'IInteractableInterface' is missing a valid Unreal prefix, expecting 'UInteractableInterface'

Is there any way to implement an interface in a UStruct? If not, is my only option then to switch to a UClass?

Thanks!

Product Version: UE 4.18
Tags:
more ▼

asked Feb 23 '18 at 09:14 AM in C++ Programming

avatar image

123099
3 1 1 4

avatar image BrUnO XaVIeR Feb 23 '18 at 12:13 PM

Even if you'd do this the right way, you cannot have UFunctions inside UStruct because, for Unreal Engine, UStructs are value types. Implementing an interface on a UStruct woudn't work.

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

1 answer: sort voted first

No, reflection system does not support interfaces in structs, as well as functions which is what you trying to do. But it should work in C++ as long as you not use U-macros on them and potentially you can make static Blueprints nodes to manageable them in Blueprint (for example make function in blueprint that calls struct function).

more ▼

answered Feb 23 '18 at 03:09 PM

avatar image

Shadowriver
37.3k 936 172 1117

(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