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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Class with a dynamic custom component

Hi, wanted to do the following:

i have this component:

ICustomInt | | |ACustomComponent | | |ABCustomComponent | | |___ACCustomComponent

Now, i want to create a custom Actor class:

ACustomClass

This class could have any on this ABCustomComponent or ACCustomComponent, is there any way of make this possible? i try with TSubcalssOf but this didn't work, any one have any advice on how to make this possible? of i will have to create a custom class for each.

Product Version: Not Selected
Tags:
more ▼

asked Feb 26 '19 at 04:02 PM in C++ Programming

avatar image

p30virus
1 1 1

avatar image p30virus Feb 26 '19 at 04:06 PM

alt text

class.png (16.7 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

If I understand the questions correctly, you are asking how to make an interface in Unreal Engine C++. This is possible, and you can find the docs on how to do it here.

The concept works the same as it does in normal C++, you just have to add some meta data to your interface class.

more ▼

answered Feb 26 '19 at 04:22 PM

avatar image

BenjaFriend
39 3 5

avatar image p30virus Feb 26 '19 at 06:57 PM

Hi BenjaFriend,

OK, thx interfaces clarification, but my questions really is if i can create the component on the actor as the interface???

Example:

 ACustomActor.h 
 
 UPROPERTY(EditDefautsOnly, Category = "Components")
 ICustomInterface *CustomComp = NULL;
 
 ACustomactor.cpp
  
 CustomComp = CreateDefaultSubject<ICustomInterface>(TEXT("CustomComp"))


How On the BP i will specify what type of Component i'm using??

avatar image BenjaFriend Feb 27 '19 at 03:45 PM

Ah ok, this should work:

 // ACustomActor.h
     /** Define this in your blueprint */
     UPROPERTY( EditDefaultsOnly, Category = "CustomComponent")
     TSubclassOf<UInterfaceComponent> Interface_Class;
 
     /** The actual instance of this interface */
     UInterfaceComponent* CustomComp = nullptr;
 
 
 // ACustomActor.cpp
 // BeginPlay()...
 if ( CustomComp != nullptr )
     {
         CustomComp->DestroyComponent();
     }
     CustomComp = NewObject< UInterfaceComponent>( this, *Interface_Class );
     if ( CustomComp )
     {
         CustomComp->RegisterComponent();
     }

avatar image p30virus Feb 28 '19 at 05:05 PM

Benja, so try this, but i got a question, this "UInterfaceComponent" should be a child class from UActorComponent right??

like this?

 class UCustomInterface: public UInterface, public UActorComponent
 {
     GENERATED_BODY()
 };
 
 /**
  * 
  */
 class TESTGAME_API ICustomInterface
 {
     GENERATED_BODY()
 
     // Add interface functions to this class. This is the class that will be inherited to implement this interface.
 public:
     
     UFUNCTION()
     virtual void A() = 0;
     
 };


Or Like this?

 class UCustomInterface: public UInterface
 {
     GENERATED_BODY()
 };
 
 /**
  * 
  */
 class TESTGAME_API ICustomInterface:  public UActorComponent
 {
     GENERATED_BODY()
 
     // Add interface functions to this class. This is the class that will be inherited to implement this interface.
 public:
     
     UFUNCTION()
     virtual void A() = 0;
     
 };
avatar image BenjaFriend Feb 28 '19 at 05:52 PM

Your interface class itself doesn't need to inherit from UActorComponent. The Interface should just have your methods that you want to implement in your child classes.

The components that you make to implement that interface should all inherit from UActorComponent and your custom interface.

avatar image p30virus Feb 28 '19 at 08:50 PM

Well, but the interface itself dont have a metoc called DestroyComponent() or RegisterComponent()

 ICustomComponentInterface* CustomComp = nullptr;

When i try to compile this i get this error:

 **********************\ICustomComponentInterface.cpp(32): error C2039: 'DestroyComponent': is not a member of 'ICustomComponentInterface'
 **************/ICustomComponentInterface.h(21): note: see declaration of 'ICustomComponentInterface'
 *************************\ICustomComponentInterface.cpp(37): error C2039: 'RegisterComponent': is not a member of 'ICustomComponentInterface'
 *************************/ICustomComponentInterface.h(21): note: see declaration of 'ICustomComponentInterface'

(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