So this one is beating me at the moment.
I have a set of floor tiles (squashed cubes) in a grid. When they are hit with a projectile, they turn on simulate physics and fall away. This has been working without issue.
At present, the player can charge up a shot and only shots with a power of 60% or greater are sufficient to make the floor tiles fall away, again, all working fine.
I wanted to enhance this a little and have an area of effect, the approach I’ve taken was one I had read about online, but, I’ve run into some difficulties and am struggling to resolve them.
When my projectile makes contact with the floor tile I now spawn a separate blueprint actor. It’s just a sphere collision. I added an event named Initialise which would set the “damage” and “scale” properties of the sphere, the latter being used to resize it - thus touching more floor tiles, the former used in my logic to determine whether the floor tiles should fall away or not.
The event ActorBeginOverlap is used to then get all of the actors the sphere collision is currently overlapping, then I iterate through, check the damage value, and tell the appropriate tiles to take damage/fall.
Seems simple enough right…
I have added a lot of Print nodes to get a time stamp of what was happening when, for the most part, everything happens at exactly the same point in time, however the physics based execution always comes first, this means that my Initialise event which should be setting the damage value and scale is kinda ignore, because the code to make things happen has already run, and, with damage defaulting to zero, nothing happens to the tiles.
The following is the output from an example Print node:
First shot…
[BP_Projectile_AoE_C_0] 2.770933 || Overlap :- Damage : 0
[BP_Projectile_AoE_C_0] 2.770933 || BP_FloorTile_Child_Destructible47 || Take Damage - Damage : 0
[BP_Projectile_AoE_C_0] 2.770933 || Initialise - Damage :100
Second shot…
[BP_Projectile_AoE_C_1] 11.052258 || Overlap :- Damage : 0
[BP_Projectile_AoE_C_1] 11.052258 || BP_FloorTile_Child_Destructible46 || Take Damage - Damage : 0
[BP_Projectile_AoE_C_1] 11.052258 || Overlap :- Damage : 0
[BP_Projectile_AoE_C_1] 11.052258 || BP_FloorTile_Child_Destructible46 || Take Damage - Damage : 0
[BP_Projectile_AoE_C_1] 11.052258 || BP_FloorTile_Child_Destructible37 || Take Damage - Damage : 0
[BP_Projectile_AoE_C_1] 11.052258 || Initialise - Damage :100
In the above, the first shot only hit one floor tile. The overlap event triggered after it was spawned, no damage had yet been set, then the Initialise even got called.
The second shot hit 2 unique floor tiles (registered twice against the same one, something else to potentially fix later), again, damage was still at zero, nothing happened, then the Initialise event was called.
I have tested this many times and the result is the same, thus the execution order, where-by the physics happen before the method I’ve called (immediately after spawning it) are causing me some troubles.
It would seem the order is “spawn” / “check phyiscs” / “run the next node in Rob’s code”
I obviously cant change Unreal’s execution order, so what can I do to work around this problem?
One thing I have tried was to set the area of effect blueprint to have the Generates Overlap Events turned off by default, then, after my Initialise event has executed, I set it back on - I had hoped that this would allow for my values to be set, then, at the moment I turned the Generates Overlap Events back on, it would trigger the collision. Nope. That didn’t work. Presumably because at this point the two different colliders are already within each other and are ignored.
I would really appreciate any ideas/suggestions from anyone who has perhaps done something similar.
Thanks in advance for your help/time