Let's say I want to do more than just a flash on an enemy. If I have it so abilities have elements, and it chooses an animation to play based on the element, this is a snippet of what I have going on now:
func create_hit_effect(element):
# Grab hit effect that's appropriate based on the element of the attack.
var hit_effect_string = "hit_effect_" + str(element)
var hit_effect_var = str_to_var(hit_effect_string)
var hit_effect = get(hit_effect_string).instantiate()
var hit_scene_dest = get_tree().current_scene
hit_scene_dest.add_child(hit_effect)
hit_effect.global_position = global_position```
The issue is that this is adding a node that has the explicit purpose of playing a hit effect animation and then being freed. If a scenario happens where 20~30 of these were to be spawned all at once, it results in a temporary but noticeable hit to performance if it's something that just so happens to be on the exact same frame (such as a group of enemies in the center of some kind of explosive/area of effect ability).
What's a better alternative to handle this sort of thing?