Best way to get reference to alternate AI controller?

I’ve created a blue print interface that has a function which swaps tags between controlled pawns from two different AI controllers. The function works but only if I first “Get All Actors of Class” and then loop through it casting to the desired AI controller and then use the out on that to feed into my functions “target” slot. Hovering over the node “get all actors of Class” hints that this is a “slow” operation. So I’m wondering what would be the better way in this example to get the desired AI controller as a reference. Keep in mind that my pawns are spawned at run time so I can’t drop an object reference as a variable inside and then link it’s BP in the details (Or maybe I can but I have no idea how to do that without a tangible object). Again the function is working but only by way of that node that is slow.

When you spawn the actor with spawn actor node it will return instance of that actor, but because it returns it as Actor class you will need to cast returned object to class of that actor in order to have access to it’s functions or assign it to variable or other functions arguments of that class, otherwise blueprint won’t identify it as that class.

But they are two separate classes. each with their own ai controllers. I need ai controller A to reference an object of ai controller B. Both spawn at run of the game. In my BP for ai controller A, I want to use my BP interface that both ai controllers implement. There is a function in the interface that exchanges tags between the two. But it requires a “target” BP of the other ai controller. The only way I’ve had any success as to use the node “get all actors of class” which indicates that it’s slow. I imagine down the road I won’t need “all” the actors of that class. I’m not sure I understand the solution you recommend. Are you saying I should cast one ai controller to the other? That doesn’t work. Could you break down the steps a little more specifically?