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"

Array of actors that inherit interface?

Hello. I'm trying to add a variable for my blueprint, which is an array that holds all actors that inherit the IPerson interface. The use-case is for a building that wants to keep track of who is inside the building. I would like the array to be generic, in that as long as the object implements IPerson, it can be inside the building. Is there any way to do this?

Product Version: Not Selected
more ▼

asked Jul 22 '14 at 12:23 AM in Blueprint Scripting

avatar image

151 11 17 22

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

1 answer: sort voted first

When you declare the array, you can select a type for it. Try typing the name of your interface. If its pops up chose Object 'you interface name'.

..To be honest, I never tried creating an array of interface type. So this may not work.

If that does nor work, another thing to try is to define a Base bleuprint which implements 'IPerson' called PersonBase. Then extend from this BP to create the different Person classes. Later when it comes time to create the array, select Object'PersonBase_C' as the type.

So the hierarchi will be:

IPerson ----> PersonBase --> PersonA, PersonB....

In Java terms:

PersonBase extends Actor (or any other class) implements IPerson

PersonA extends PersonBase

PersonB extends PersonBase

more ▼

answered Jul 22 '14 at 09:17 AM

avatar image

3.4k 154 52 271

avatar image Makotech222 Jul 23 '14 at 01:54 AM

Yeah, i decided to go with a base class, and have the blueprints extend it. Will the array still hold the extended classes, tho? or will i have to cast them to the base class before i add them to the array? My C++ polymorphism is a little bit rusty

avatar image mindfane Jul 23 '14 at 03:13 AM

As far as I know, the items from the array will be of the declared type of the array.

So suppose I declare the array as of type Object'PersonBase_C', then when you get an item back from the array, it will be of that type. However if you want to get the actual type (suppose you added PersonA or PersonB which are extened from PersonBase), you will need to cast them to their correct type.

But in normal cases, that cast is not necessary. If you find yourselves in need of such a cast, you need to rethink your class hierarchy. You should define all the required functions that the Persons should expose in the base class itself. Then you can override them in the extended classes. The overriden version will be called even if they are not cast to the real type.

(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