(Note: When i set one or the other as the active the default pawn class, everything works. Its when switching between the two during run time is where the problem occurs)
The problem here could be a lot of things, and depends entirely on how you coded it. I think @eblade probably guessed the most likely culprit, but if that doesn’t work, you could always try just turning the AI off and on again.
This might work:
Or maybe this:
Edit: I realize I plugged these into begin play. That was just because it was a stand-in event I could find. I was talking about the other nodes. You can ignore that they are plugged into begin play and plug them into where you need them instead.
I’m assuming that i want to restart logic and change the blackboard value as soon as one or the other playable character is active. So, it should look like this inside their blueprints?
I’m having a bit of trouble with getting this to work. When i try to change the target actor or restarting the logic of the ai controller, nothing happens and im still getting the same result.
This could be a lot of things. The last attempt at an “easy fix” would be to have a dummy behavior tree that you tell it to run for a moment and then swap it back to its “real” behavior tree. That is basically like “respawning” an entirely new version of your behavior tree, so it should act the same as if you just hit play and the AI just loaded (which you said it always works at that part).
If that doesn’t make it work, then there must be some fundamental difference between a character that starts in your game and a character that you swap in. Maybe it doesn’t recognize the swapped characters as the current player somehow, but that depends entirely on the coding.
I had to change some of the code in the BT but i actually managed to get it to work. @Detach789 It turns out it wasnt recognizing the player characters for some odd reason.
The behavior tree was still getting the distance from both playable characters even after running into the error of not moving after it did, so i’d assume it had something to do with the code but at the time nothing seemed wrong.
I looked at my BT and noticed that i have “rotate to face bb entry” node placed in the necessary spots but it wasnt working til after i disconnected them. The odd part of it was that in the ai controllers BP, the “TargetActor” black board key was set to player character, so i’d assume it would get any player character as the that key, which it did but only when one or the other character was the default character.
Finally i just got rid of the target actor and create a BTTask that follows any other playable character and then made the AI enemy rotate its body to them.