playMaker

Author Topic: Array List compare  (Read 773 times)

curb47

  • Sr. Member
  • ****
  • Posts: 256
Array List compare
« on: February 08, 2021, 07:59:13 AM »
Hello,

I'm trying to work out how to get 2 Arrays compared for further actions.

When a bunch of enemies are spawned, they are stored as object in an Array:

Drones - drone 1, drone2, drone 3, drone 4, drone 5

Because of what I've been reading about, and experiencing, if I remove objects from an array it can cause weirdness, as the array list is created as a 'snap shot' of a bunch of objects and isn't meant to be dynamic.

So, when a drone is killed/destroyed it is not removed form the first array, it is added to another array:

deadDrones -

drone 2, drone 4 (for example)

The are a few things going on the game that mean an event must be sent to all of the drones that are still alive, so I need to compare the Drones array to the deadDrones array, almost like Drones-deadDrones = alive drones, and send the event to those.

Or can i just send an event to all objects in the array, and if they're Null/destroyed it will just ignore it?

Thanks.

J.



ch1ky3n

  • Full Member
  • ***
  • Posts: 208
Re: Array List compare
« Reply #1 on: February 08, 2021, 11:47:44 AM »
Is there any particular reason why you should save the dead drones as an object instead of bool or string?

I believe your drone are prefabs right, so isn't that much better if the prefab store something on the arrayDeadDrone telling em that they are dead? rather than transferring the prefab into the array?

anyway, you must have the reason, so if you want to do so,

you can send an event to that alive drones, there is an action on the ecosystem that enables you to send an event on every object inside the ArrayList (btw, you're using array maker right?)

another way is to send and iterate through those alive drones of course.

you could also make a parent GO and all drones spawned is spawned under this parent, then you can send the event on the parent and tick the "include child". this will be received by every drone under this parent GO

If the game object is not active, the event will not be going through.

Good Luck

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Array List compare
« Reply #2 on: February 08, 2021, 12:18:26 PM »
Hi ch1ky3n,

Thanks for your ideas.

Yes, the drone is a prefab. I set up the array deadDrone just as a way of being able to sort out drones that are still alive, as I need to be able to send events to the drones, telling them what to target - the mothership or the playership.

I have no particular reason for transferring the prefab to the array, rather than a bool or string, it's just my limitations of understanding.

In a nutshell, I'm trying to set up a little wave manager; one 'squad' starts out as a pooled prefab which consists of one parent containing up to 10 empty game objects arranged in a pattern. At GO, the children of the parent are put into an array, and used as spawn points, then, the FSM runs through the array and spawns a Drone (pooled prefab) at these points.

The drones stay as children, in formation, and the Parent (squad spawner) has a simple Move Towards action to target the mothership.

If the 'squad' of drones comes within range of the mothership, they all peel away one by one from their position; being de-parented, and using Look At Smooth, Apply Force, rigid body physics engine etc, and attack the mothership.

However, if the 'squad' of drones is intercepted by your player spaceship and attacked, the drones all spread out (subtle Explosion action), are de-parented, and now target your play spaceship and attack you.

After 10 seconds of attacking you (player), they turn their attention back to the mothership and swoop away.

You can chase them again, and when you shoot one, just before de-spawn the drone sends an event to all alive drones to turn their attention back to the player.

Does that make sense? I'm trying to establish a simple comms system between the drones, so an event can be sent to either target the mothership, or target the player.

Once all the drones of that wave are destroyed, the squad spawner is de-spawned.

So, maybe I'm over thinking this? Essentially, I want to create a dynamic list of the alive drones (pooled Prefab) that can receive a Send Event.

On this thread I posted a couple of days ago, there are some screen grabs of the set-up. It's relating to a different issue (solved) but it'll give you a clearer idea:

https://hutonggames.com/playmakerforum/index.php?topic=23425.0


I hope that makes sense?

Thanks.
« Last Edit: February 08, 2021, 12:20:48 PM by curb47 »

ch1ky3n

  • Full Member
  • ***
  • Posts: 208
Re: Array List compare
« Reply #3 on: February 08, 2021, 02:51:14 PM »
Alright, based on your explanation, it looks like the player Ship and the mothership are teaming after all, and the drones are the baddies.

The baddies are in form of empty GO, arranged in a formation under spawn manager and you registered those points on an array

-Here I suggest you make 2 arrays. One array called ArrayFormationCoordinate is storing the position of your formation coordinates. the other array (arrayAlive)is to storing the drones that are alive. If you spawned 10 drones, naturally, this array will have 10 entries right.

at the start of the game, those empty GO should register their formation vector3 to the arrayFormationCoordinate. Then, you spawn prefabs using those coordinates as their spawn position.

now the spawn manager is moving toward the mothership and within a certain radius, they detached and start doing their stuff.

the player starts shooting on those pesky drones and eventually, one of them is dead (Despawn). here, you can remove the destroyed drone object from "arrayAlive".

so the arrayAlive now has 9 drones left

After 10 seconds of attacking you (player), they turn their attention back to the mothership and swoop away.

in case you need to assemble those roaming drones back to position again, you could retrieve each drone to each position right ? drone index 0 from arrayAlive goes to Coordinate at arrayCoordinatePosition on index 0, and so on until no more drone left. This will let them get back together neatly in a formation (1 missing though). You could also reparent them to the spawner.

then you send the event "ATTACK MOTHERSHIP" to the spawner using send event action game object and include all children ticked.

So, maybe I'm over thinking this? you're not, there is nothing wrong with the setup.

here some that maybe help if it is in line with your game design:

1. The spawner should stop moving during the fight if possible, so you don't have to parent and reparent again (since the parent is not moving)
2. The misfortune drones that died, could send something on a whole new "arrayDead"  before despawning, in case you need to record something. maybe the time of death, or unit number, etc in case you need it
3. don't forget to revert the state back to its original before despawning it
4. Maybe instead of using gameobject as a point, you could store the vector 3 instead inside the arrayFormationCoordinate.

Good Luck

PS: The game look fun, good luck with it
« Last Edit: February 08, 2021, 02:52:51 PM by ch1ky3n »