Return Target Index Before Performing Action

Hi all

I am trying to determine if there's a way to obtain the enemy target index of a skill before the skill is executed. After I select my skills for all actors and determine the targets, the data must be stored somewhere I'm assuming. I just can't figure out where.

Some searching has led me to BattleManager._action._targetIndex, but as I understand the index is returned after performing the skill in this case. Using the damage formula is no good either as it needs to run before the target index us returned.

Could it be somewhere in the $gameActors.actor()._actions[] array? I know the selected skill ids are stored there, so maybe the target indexes as well?

Any help or hints are appreciated!
If you use Yanfly buffs and states core, you can try to find it through Custom initiate effect notetag, because the user's target will surely hold his ID somewhere inside himself.
I've looked through the buffs and states core plugin and what I found was target.index(), but I can't seem to find where target itself is defined.

Some searching has led me to BattleManager._subject.currentAction().makeTargets().clone()[0]._enemyId, which returns the enemy id (not the index but I can live with that) of the current actor's target. It even returns the value before the actor even executes the skill.

I am certain the IDs for all actors' target IDs are stored in an array somewhere. Can't figure out where though!
You can grab that info in the actor action array.
Code:
$gameActors.actor(actorId)._actions[actionIndex]._targetIndex

I ran an event at turn start: it runs before any action take place. I had it send to the console actor 1, and then pause combat execution by putting a message. The actor action array contained the info you seek each time. The battle manager action object contains only the action being processed. In that case it was appropriately empty (null) because the event runs before any action can take place.
You have to keep in mind though that if the target dies or is rendered untargetable before the action can take place, it will select another target at random once the action is executed.

Disclaimer: I use a lot of yanfly's plugins, so that info may not translate in a vanilla game.
Thank you @Astfgl66 !

Original thread: https://forums.rpgmakerweb.com/threads/return-target-index-before-performing-action.82201/