Spawn one explosion not two?

When BombActor overlaps another BombActor it runs the SpawnExplosion Function.

This SpawnExplosion Function simply spawns the ExplosionActor which then activates it’s particle effects within itself (ExplosionActor).

The problem is that BOTH of the overlapping BombActors call this spawning of the Explosion Actor which results in two explosions.

This seems so simple, but I can’t figure out how or where I should handle this call to spawn the ExplosionActor.

Thank you in advance.

You need to find a way to set a boolean on one of them that would allow a branch that doesn’t spawn the particle for that actor, but you’d also need it not to set the boolean on both actors, thus defeating the purpose.

Exactly, each thing I have thought of just won’t work. I wish there was something like a persistent blueprint (Not the level blueprint) where I could implement a blueprint interface that then calls these functions instead of the individual actor. Explosions, sound effects, etc.

You could give your bombs a random number when they are spawned, and for example, only the bomb with the higher number will spawn the explosion, the SpawnExplosion should have a bomb reference input “Hit Bomb”, which you set as a reference to self when you are calling it. Then check in the spawn explosion function if the Hit Bomb’s number is higher than it’s own, if it isn’t then spawn the effect, otherwise return. You could even use, world X location or something else arbitrary to decide which should spawn the explosion.

Also, should both bombs be destroyed on overlap? I think rather than having them destroy each other, have the overlap event set self to hidden in game (after everything else) and after a short delay make it destroy itself, you might not be having any problems with that anyway though.

This is something that may work. Not exactly what I am looking for. Will give it a try if no other options pop up. Thank you!

I’m not having any issues with that currently. Thanks for the suggestion however.

There are a lot of Classes that you could use for that. You could create a logic for that in the GameState
or spawn your own BombManager in the GameState and save it in a Variable, so you can access it, but
all in all that still requires you to figure out a method to check that only one bomb can call the explosion.

Just a small note here: You are making a network game. The Overlap function is called on Server and Client.
So the Explosion actor will get spawned on both. But you only activate it on the Owning Client, which means you
assume the Overlap is only called by the Server. Make sure to use “Switch on Authority” to really limit the
spawning etc to the Server (and set the Explosion actor to replicate, so that the Server Spawn also spawns it for the client).

My idea:

Create your own GameState Blueprint. Create a function in there called “Try Spawning Explosion”. Give it a Transform as Input.
When overlapping in the Bomb, get the GameState, cast it to your GameStateClass and call the function + passing the Transform.

Now in the GameState, create a Variable of type “Explosion Reference”, so that you can store the spawned explosion Actor.

In the TrySpawningExplosion function, you now FIRST OF ALL check if this reference variable “IsValid”. Which checks if the Reference
is empty or not.

If it is EMPTY (so not Valid), spawn a new explosion, save it to the Variable and call Activate on it.

if it is NOT EMPTY (so Valid), don’t do anything.

Why? Because when spawning the Explosion and saving it, the Variable gets Valid and the next Bomb can’t call the Explosion
until the Variable is NotValid (empty) again.

It get’s empty by the GarbageCollector as soon as you Destroy the Explosion Actor, but you could also clean it manually from inside
the Explosion actor by just getting the GameState again and setting it to nothing.

Make sure to set your custom GameState class in the GameMode settings, like you do for the Controller and stuff.