Finding The Reference Of An Object Being Used By A Script

Hello and good day everyone!

I have a script that is not attached whatsoever to a game object, that basically somehow (I’m not clear on all the details, apologies) acts on game objects.
What I need to be able to do is find an object that is using that script within the script itself.
To maybe make things more clear, here’s how things are set up.

I have a class called SwingSword, and it, well, swings a sword that’s attached to an enemy. It does not inherit from MonoBehaviour, nor is it ever attached to any game object at any time.
I have the enemy itself, and it can be instantiated throughout the world. Virtually everything on it does inherit from MonoBehaviour (the exception being some non-Monobehavior AI stuff.)
I need to be able to know which game object SwingSword is affecting at any given time so that I can have an instance of certain scripts on the enemy inside SwingSword, thereby only affecting the enemy that needs to be affected, and not all enemies or some random enemy.

If it helps any, this entire scenario was made possible with RAIN AI, and from what I can discern, how it works is that the SwingSword script is accessed through the behavior tree, and that behavior tree is then instanced on an enemy. The behavior tree itself is never attached to a game object, but there is an interface in the inspector that references this behavior tree.

I do hope this makes sense, thanks for your time and have a great day!

Hello everyone, I seem to have found an answer!

It appears to be relatively simple to do this kind of thing, although you need access to the AI rig, so the following has to go, as far as I can tell, in the Start(), Execute(), or Stop() methods in a custom action.

scriptInstance = ai.Body.gameObject.GetComponent<script>();

As far as I can tell, that’s all you need!

Have a great day everyone!

P.S. If anyone has any other ideas on how this could be achieved, do let me know, that would be awesome!