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"

Is there a callback that is called when a new component is added to an actor?

I have a class which is an actor and I would like to enforce that only the components that implement a particular interface can be added to this actor. And I would like to do this component validation in C++ code.

Is there a way to achieve this both at Editor time and at Runtime?

Product Version: UE 4.15
Tags:
more ▼

asked Apr 19 '17 at 08:13 AM in C++ Programming

avatar image

Matiati
154 17 20 39

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

1 answer: sort voted first

I don't know of any callback, but there is the function AActor::AddComponent ( https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AActor/AddComponent/index.html ). I would strongly guess that this is called internally whenever a component should be added to an actor. So for your actor in question you can override this function and if the component implements a certain interface, call the parent method, and if not, simply return NULL (and see what happens, because I havn't tried it and don't know what will happen!).

more ▼

answered Apr 20 '17 at 04:05 PM

avatar image

Benergy
831 21 4 29

avatar image Matiati Apr 24 '17 at 07:41 AM

Thanks for the answer Benergy. But I am afraid AddComponent is not a virtual function (I've checked this both from source code and documentation). Therefore it cannot be overridden in classes that inherit from AActor.

If it was doable then this would be an elegant 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