Get Array Type from an empty Array ?

Hi,

Sorry if this is a dumb question; I’m an unreal newbie.

In blueprints, is there a way to get the class from an empty Array variable? I have an empty array of a specific actor type, but I am populating the array with a function. The only way I can find get the type from the array is to get a copy of an indexed object from the array and get it’s class.

Is this the only way? I would have thought that since the array has to be typed you would be able to get that info from an empty array without it having an indexed item. I am a blueprints newbie.

Thank you!

What are you trying to do exactly?

You have to give the array a type, therefore you know at design time what the type is.

If you create an array of type “AActor” objects and add spawned actor references to that array, then all you get from the array are AActor. If you add an object to this array which inherits from AActor , such as APawn or APlayerController then they will still be stored as “AActor” in the array, but you can cast to APawn or APlayerController per element of the array.

Hi

So, I was trying to make the top function more modular so I could reuse it potentially with another array of a different type. I guess it’s a pretty stupid function anyway… well, I made the bottom function, but it doesn’t work because the array is empty.

I guess I could just pass the function both the class and the array, but I thought it would be cleaner if I could do it this way somehow because it would eliminate the possibility of passing it an array that was not typed the same as the class I wanted to spawn in. Is that not possible since it’s empty?

Thanks for your guys help!

Doesn’t quite make sense.

If you spawn an actor you have created an instance of that actor. This is the blue output that you are adding to the array.

So it is like you have said, “given a class, create an instance of that class, and then I’ll store a reference to that instance in an array”

Then in second function, you are getting a ref to an instance and then spawning a new instance of the same class type. But this won’t work if the array is empty and you are not checking that the index is valid. It seems most likely that you are misunderstanding what some of these nodes are doing.

Just in plain language can you describe what you want to do? If you want to selectively spawn certain classes you could use something like an enum plus a select node to handle a case like that. I can show examples but it would be better to know exactly what you aim to accomplish.

Hello this is not necessarily dumb, but you can’t do this in Blueprints alone.
You need to access the array property’s reflection data (= type information), which can only be done through C++.
Most builtin array functions (KismetArrayLibrary.h) use similar idea to provide wildcard nodes that work with arrays of any type. They resolve the type at runtime. The keyword is CustomThunk. It’s a bit on the complex side, so if you were trying to avoid C++, you better try to find a different way.