Dummy Child with Tag (for findGameObjectsWithTag) - any caveats?

Hey guys!

This is my first post here - woooo! :slight_smile:

So I am working on an isometric RPG and am handling target acquisition for NPCs/creatures.

I thought about adding a dummy child EMPTY to all characters, called “faction”. This child would consist essentially only of its TAG (which would then be “allies”, “enemies”…), so that when an AI wants to select a new target, it does a FindGameObjectsWithTag and can search for the appropriate tag (e.g. “enemies”) and set the respective empty’s parent as the new target (WHICH enemy is finally chosen would depend on distance etc.) – is this a very bad idea? :smiley: Performance would be important, as the target platform is mobile.

Are there any significantly better alternatives to this? Like keeping a list of characters in each faction, then going through that list?

Thanks so much & I hope you had a great Christmas! :slight_smile:

I would recommend creating a List, because FindGameObjectsWithTag is relatively slow. How are you selecting a new target? There will be ways to optimize that, too. If you’re selecting a random enemy, you could simply do enemies[Random.Range(0, enemies.length)]. Are you doing distance? In that case, you could always do a Physics.OverlapSphere() with a given range to select a portion of the enemies.