Behavior Trees for Player Controller?

I have used Actor Components to share some checks and functionality between my Player Character and AI Characters. For example this was used to check if a melee attack is possible:

Now I’m trying to migrate all Actor Components like this into modular Behavior Trees. I have had some success in using the tree below with an AI Character:

But I’m not sure how can I share it now with my Player Character? With components, all I needed to do was to add it to a Character, maybe also hook it up to the Controller, and it worked.

Is there some similar mechanism to Behavior Trees but for Player Characters? Or maybe my Player Character should actually be a simpler AI that somehow gets input? I don’t want to duplicate logic in both Actor Components and Behavior Trees…

Another idea I had, would be to keep all checks in Actor Components and call them through Behavior Tree Tasks, but then I would lose the flexibility of decorators.

ASAIK, you can only have one controller per character, however if your method works, I would love to see a tut on it.

Why are you moving the logic out of the actor components and into behavior trees?
You can keep all the functionality in components and ahve your AI communicate with the components just like the player does.

@Roy_Wierer.Seda145 But doing it in Behavior Trees makes it much more understandable, easier to debug, and in general - that’s what they are for.

I found this thread Is it possible to use both AI Controller and Player Controller with the same pawn? but it’s pretty old, and in the end there was no clear answer.

I think the reasoning makes sense. In RTS games, for example, there are many characters that are both AI and Player Controlled (if currently selected). So there must be a way to do this.

In common RTS you don’t really have any pawn, you command concepts like squads to which characters respond. Might be possible to just spawn an AI Controller from code and run a brain component on it without it controlling a pawn… but that needs some testing and I’m not convinced yet XD, I use c++ whenever I can and try to avoid these visual state machines.

I followed the thread I linked before (Is it possible to use both AI Controller and Player Controller with the same pawn?), did some experiments and got it working. Now I have a “Semi Player Controller” and “Semi AI Controller” both influencing my Character.

What was missing from the instructions in the thread:

  1. Your “Semi Player Controller” should, in the Event On Possess method:
    a) spawn a “Semi AI Controller” and hold it as a variable
    b) spawn the Character and possess it with the “Semi AI Controller”
    c) switch camera to the one in Character, by using Set View Target with Blend
  2. Create events to receive input in the “Semi AI Controller”. Then invoke them when you receive actual input from “Semi Player Controller”.
  3. Camera will break… So far the only way to fix it I found is to:
    a) in “Semi Player Controller”: Auto Manage Active Camera Target = OFF
    b) in “Semi AI Controller”: Set Control Rotation from Pawn = OFF, and on tick (yeah…) you need to Set Control Rotation to match the Camera (not camera boom!) rotation
    c) in Character: Inherit Pitch/Yaw/Roll in Spring Arm (camera boom) = OFF, Component Replicates = ON
    d) when you want to rotate you need to rotate the camera boom instead of using the controller methods (because the pitch method will NOT work in AIController, see unreal engine4 - UE4 How to set pitch in controlRotation for AIController - Stack Overflow)

I think that was all. Then you can run a behavior tree and pass your input as a bool, which you immediately have set back to false in a behavior tree task before performing an action, otherwise it will just loop. Passing axis values (movement, camera) to a behavior tree seems impossible, because the parallelism is very limited and one action would block the other.

I’m going to keep building on top of that and see if there are any issues down the line, but so far it works (even in multiplayer).