Combining variables of the exact same blueprint together

My blueprint has a Planet with an array of numbers. I have multiple instances of this planet in my scene. I want them to be able to crash into one another and combine their values.


Example:

Blueprint_Planet, Array1 = 10, 10, 10

Blueprint_Planet, Array1 = 5, 5, 5 —> Destroyed

Then, the first planet should now has the values of : Array1 : 15, 15, 15


The trouble I’m having is when they hit each other, they BOTH go off, and overwrite each other’s values before being destroyed. I don’t want to make an additional blueprint to keep track of each planet. Is there a way to simply combine the values of these two arrays without other blueprints involved? Or an easier solution?

=======

Looking at the Scene picture (in the upper left, reading from bottom to top)…
The printed values, after the first hit should be 200, but it’s 300 instead. Then any hits thereafter are incremented by 100 as it should.

You see:
index = 0 ||| 300, then index = 0 ||| 400.

It should be:
index = 0 ||| 200, then index = 0 ||| 300.

I think because they are the same blueprint and they are BOTH firing, it doubles-up. Any way to prevent this or another method to simply combine the values?

Thanks,

To me, easiest solution would be to distinguish why 1 planet would be destroyed vs the other. This could be size, velocity, age, color, whatever you want. Once that is established, use it to branch down two paths:

  1. The planet destroyed
  2. The planet that survives

This should prevent the planets from destroying one another, and make it easier for you to organize your values. Use the winning planet to take and add the array from the losing one.

Another possibility would be to have a boolean flag in your planet BP to indicate when a planet is being collided with. That is, set the “colliding” flag to false in BeginPlay; when your OnComponentHit event fires, check to see if the “colliding” flag is true. If it is, stop. If not, set the “colliding” flag of the other BP to true, and continue. That way, the event would only execute in one of the BPs.

Thanks for the input! I really needed both of you EvanDoody and VolatileAgent to get through this one. I did a combination of your two pieces of advice. I ended up making a PLANETID that is on a different blueprint, but still kept each individual values on the Planet itself. The issue was when DestroyActor was called, my advice — don’t mess with destroyed actors data, real headache. So I ended up passing the arrays to my planetspawner event, this adds the PLANETID to a different array. Once this array reaches two, it then spawns a new planet with the combined arrays values.
247002-

Thanks!

See above comment, thank you as well! :slight_smile: