I am using 3 arrays to keep track of missiles for a weapon system.
Weapon System has 30 “Slots”, one for each missile.
Index in each Array corresponds to a “Slot” in the Weapon System
Array #1: Array of Scene Component Object References and is Preset at Begin-Play with all the Scene Components which mark the locations for the missiles to Spawn and be Launched from. 30 Indexes (0-29).
Array #2: Boolean Array and is used to track if a Missile is Built (Finished Building and Spawned) in the particular “Slot”. 30 Indexes (0-29).
Array #3: Array of Actor Object References and Index is set to Object Reference of the Missile Spawned in that corresponding “Slot”. If there is no missile spawned, the index is set to “None” by the engine - to do this, when the missile is Launched, I use “Set Array Element” and Using this Array and the appropriate index number and leave the “Item” pin not connected and the system then sets it to “None” (Thats what it says when I watch the array variable in debugging)
When a Missile is finished building, a script checks the next spawn location to see if a missile is already built, if it is it goes to the next one until it finds an empty one - I use the Boolean Array to check this.
That Array Index is passed on to then get the Corresponding Scene Component to Attach to, Spawns the Missile while setting the Index of the 3rd Array to the object reference of the missile spawned and attaches it.
I then have a complicated script for targeting enemies and assigning the Homing Target Component for each missile, tracking if the missile already has a target. And more arrays for tracking that information.
I am accustomed to arrays in PHP, where a key->value both could be alphanumeric or references to objects. They work more like Maps in UE4 however Maps are not editable (well, not really or easily anyway). In PHP I could have easily keep track of the info in all 3 Arrays in a Single Array in PHP, with he Key being the Scene Component Object Reference and the Value being the Actor (Projectile) Object Reference and would also be able to check for a null value (If missile not built, value would be null instead of object reference)
Basically, if I was able to directly change key->values in Maps this would be easy. But to do that you then have to temporarily store the Map Key->Value, Remove the Key and then reinsert the Key with the new Value. And I do believe this changes the order of the map? In PHP with Arrays, it would keep the same order and I could just simply update a value of a particular key as well as reference an index number.
I have the system working but I am wondering if I am missing something with Unreal Engine and there is a simpler, better or more efficient way of doing what I did? I am finding as I am adding the Targeting scripts it just gets more and more complicated and troublesome.
Maybe this is a topic for the forum? If this is better to post on the forum let me know and I will change post to somewhere appropriate on the forum.