Event tick and delay - alternatives

Hi everyone.
Long story short, I have a spaceship with several guns, each gun is finding the closest enemy pawn and I want to visually distinguish selected targets
I made the simplest approach, every tick on the spaceship blueprint I’m sending a signal by using BPI to the target pawn that changes material on the enemy pawn, and if there is no signal for some time the material switches back

It works well but I want to find an optimal way in this kind of situations

I’ve tried to send additional BPI signals for all other enemy pawns to switch back their materials

But it doesn’t work because there are 2+ guns and they interfere with each other
I will be glad to get any advice on how to handle such situations with event tick and delay

Just idea:

  • give each target/enemy ship integer ID number. In constructor blueprint increase some global value (in player pawn, or game mode etc) and get integer ID for each spawned enemy.
  • each weapon on changing target should get target ID number from targeted ship and store it
  • make array of targeted ships in player controlled ship (clear targets array, then loop trough all weapons and build array with updated ids)

then either all enemy ships read that array and test if their id is in array (pooling will get slow with 200 or so enemy ships at once)
or make dispatcher that sends this array every time you change targets. (better performance but it really does not matter until you get huge numbers of enemy ships).

To switch back after some time use interpto, start with for eg 10, and interpto back to zero, set speed (or max value) to change how long targeted material should be visible.

To have independent counters for each weapon targeting, you should create array of such counters then every time you want new weapon target ship you add to array. This will let you set different timer length per weapon.

However if all weapons have same time to show target, you just refresh that interpto counter to max on every new targeting event.

This whole thing with weapons and targetting is not easy to design. I would code all weapons as separate blueprint actor that is spawned on ship. Then inherit from that target and create different visuals projectiles etc per weapon, but with core (parent) code same for all weapons.

Then for targeted enemy spaceships either create base spaceship (just like for weapons) and inherit for new visuals only ship. Or spawn blueprintable components on hit/targetted spaceship. Yes this sounds complicated, but blueprints grow really fast really big, imo it is better to have some extra code and all blueprints split into smaller actors, than one huge blueprint that does everything.

1 Like

Thanks for advice