How do you even optimize a tower defense GUI game?

So I was just playtesting a GUI-based tower defense game I’ve been working on. Script activity was at over 60% when 40ish enemies spawned…

Every frame, I update each enemy and use magnitude to determine how close they are to their target node. (for their path movement, to know when to change their direction.)

Apparently, that’s very expensive. I can’t really do anything else though, because for projectiles I’m going to be using similar collision code to determine if it hits an enemy, I’d have to iterate over all the enemies for each projectile to see if it’s touching any of them.

Magnitude doesn’t even seem to be the culprit, it appears any arithmetic operation on the Absolute properties seems to make that activity rating spike.

Any tips for optimizing this? I didn’t experience any FPS drops, but 60% activity is something else…

Maybe make a custom magnitude system?

I’m gonna bump this because I have no idea how to go about it.

I originally wanted to give projectiles functionalities such as piercing numerous enemies and dealing area damage, but that doesn’t seem possible to do without using AABB collision code or magnitude checks for each enemy on the map…