So just to make it clear, im not asking how to make an array in C++, I know how to do that. I’m wondering if there is a way to mimic the functionality of the make array node in C++ so you can just make an array and input all the elements right away without having to make a specific variable for it.
Hi Newj2,
No, c++ has to have the types all defined before you can add (or you could use an array of void* 's, buts that’s not good practice).
Strongly typed variables can save a lot of headaches later…
I understand that you have to have the types defined, but is there a way to define the type of an array in C++ and immediately after that add two different items to it like you can with the make array?
Only if they both derive from the same class and you’ve defined the array as TArray<MyBaseClass*> - I think you’ll find that MakeArray is bound by that same rule - it will probably use something like AActor* as the BaseClass…
In both Blueprint and C++, all items in an array need to share some base class.
This might be UObject*
, or AActor*
.
You can put objects into such an array as part of the construction process:
ACharacter *player1 = ...;
APawn *enemy2 = ...;
TArray<AActor *> myActors = {player1, enemy2};
Ok, that explains how to do it and the syntax for doing it, it didn’t show in the documentation for that, thank you!
Because the C++ documentation assumes that you know the language and can interpret the list of constructors to do the thing that you want. In this case it’s the constructor with the “Initializer list constructor” description listed in the docs that jwatte is using.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.