Behavior Tree Stuck

nitrox32

Member
I am trying to get my character to repeatedly swing a sword after a short cool down time. I've attached a screen shot of a simple tree involving a sequence of a Start Stop Use and a Wait behavior. When I run this tree the character uses the item correctly but the tree just freezes after that task is complete and doesn't complete the Wait task. I have set a break point on the Wait task to confirm this. I have tried unchecking Wait for Use Complete. This executes the Wait task however after returning to the Repreater and restarting the Sequence, the Stop Start Use task returns a failure the second time and the Wait task doesn't execute. The Use Item Start and Stop type are both set to Manual in the Ultimate Character Locomotive component.
 

Attachments

Last edited:

Justin

Administrator
Staff member
It looks like the wait task was run from the second screenshot but I would ensure there is an always active task that is running so your tree doesn't restart as soon as both tasks have been completed. Placing something like idle instead of wait would do the trick.
 

nitrox32

Member
I just replaced Wait with Idle. I guess the real problem is the repeated sword swing animation. On the first time the sword swings and the then the idle task is executed. After both the Start Stop Use and Idle tasks are executed (green) the Repeater restarts the Sequence. However on the second time, the Start Stop Use task executes (turns green) but the animation doesn't play. I'm looking to have the sword swing each time the behavior tree is repeated.
 

Justin

Administrator
Staff member
My guess is that it is a problem with the way that your sword is setup and not the actual tree. I would add that sword to your player character, get it working correctly, and then move the settings from the player's sword to the AI's sword.
 

nitrox32

Member
Perhaps, but I'm not sure what I'm missing. Attached is a sample scene. It has Nolan with the sword attached. The behavior tree is set to use the sword then repeat. The sword swings only once then just stops after one use even the though the repeater is set for forever. Why is this?
 

Attachments

Justin

Administrator
Staff member
When I tried your scene the agent continuously attacked without any changes. It was playing the punching animation though so I changed the Animator Item ID to 22 instead of 21 for MySword. Beyond that I didn't make any changes.
 

nitrox32

Member
Thanks for looking at the scene and correcting the Animator. Anyway, the agent still goes back to idle after one swing. I'll try it again with a fresh project. I'm using unity 2018.3.11f1 and the latest version of UCC and BD.
 

nitrox32

Member
I've updated to UCC 2.1.3 and Unity 2019.1. Started a fresh project and now things are worse. I'm trying to keep my frustrations at bay but It's becoming difficult. Once again I my goal is AI character to repeatedly swing the sword. BD locks up after one swing just as the images above show. I've sent a sample scene and your response was not much help. Let me go through my steps.

1) Create a new project with UCC and BD. Nothing else. I drag the UCC integration package into the scene.
2) Create a plane and scale it by 4. Add material. Mark as Static and bake NavMesh.
3) Tools -> Opsive -> UCC -> Main Manager
4) In Main Manager: Setup -> Project Tab -> Update Buttons and Update Layers
5) In Main Manager: Setup -> Scene Tab -> Add Managers
6) In Main Manager: Camera Setup Settings: Perspective -> Third, Third Person View Type ->Third Person Combat, State Configuration -> DemoStateConfiguration (StateConfiguration), Profile ->None
7) Click Setup Camera
8) Drag Nolan Prefab into the scene
9) In Character Setup: Perspective -> Third, Third Person Movement -> Third Person Combat
10) Drag Nolan from the hierarchy to Character slot
11) Leave Model Type as Humanoid
12) Change the Animator Controller to UltimateCharacterControllerDemo
13) Advanced: Leave everything as is except check AI Agent and NavMeshAgent
14) Click Build Character
15) Click Create when Ragdoll Window appears
16) Close Manager Window
17) Run the Scene and to check for errors. I receive one warning and one error. The plane also disappears and the camera seems to be attached to Nolan's foot.

Warning: No character has been assigned to the Camera Controller. It will automatically be assigned to the GameObject with the Player tag.
UnityEngine.Debug:LogWarning(Object)
Opsive.UltimateCharacterController.Camera.CameraController:Awake() (at Assets/Opsive/UltimateCharacterController/Scripts/Camera/CameraController.cs:187)


Error: Unable to find the character with the Player tag. The camera will be disabled.
UnityEngine.Debug:LogError(Object)
Opsive.UltimateCharacterController.Camera.CameraController:Awake() (at Assets/Opsive/UltimateCharacterController/Scripts/Camera/CameraController.cs:190)

At this point is see no reason to continue adding the Behavior Tree as I don't know if these are part of the problem. I have attempted to fix the problem by adding Nolan to the Character slot in the Camera Controller. The warning goes away but then produces these repeating errors:

NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Camera.CameraControllerHandler.FixedUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Camera/CameraControllerHandler.cs:129)

NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Camera.CameraControllerHandler.Update () (at Assets/Opsive/UltimateCharacterController/Scripts/Camera/CameraControllerHandler.cs:100)

I get these same errors if I change Nolan's tag to Player.
 

Justin

Administrator
Staff member
Because you are only working with AI agents you do not need to add the Ultimate Character Controller camera. I've attached the scene that works for me where I modified the Animator Item ID.
 

Attachments

nitrox32

Member
Nope, still not working. One swing and just stands there. I checked, I'm using BD 1.6.2 and UCC 2.1.3 and Unity 2019.1.0f2. I have a video of the behavior. But it's to large to attach. No errors or warning in the console. I've at least attached a picture of your scene during run time.
 

Attachments

nitrox32

Member
I just uninstalled Unity 2019 and reinstalled it. No other copies of Unity are on my computer. I deleted anything having to do with Opsive on my computer as well. I created a new project and installed UCC, BD, Movement Pack and the UCC intergrations package. I recreated the same scene (without the UCC camera controller as you suggested). Now Nolan will swing twice before the behavior tree freezes green like the images above (progress I guess). Perhaps I have an older copy of the UCC integration? Any other thoughts? I've attached the new scene.
 

Attachments

nitrox32

Member
Got it! Now Nolan is repeating his actions. Now the problem is the if I put the Start Stop Use in a Sequence with a Wait task, the only the Start Stop Use task is executed repeatedly. I'd like Nolan to have a cooldown time. I have tried checking Always Return Success in the Start Stop Use task. I've attached the scene (you can ignore the Scene1 in the last post).
 

Attachments

Last edited:

nitrox32

Member
Finally got it! Sorry for the quick posts. I had to uncheck Wait For Use Complete in the Start Stop Use task. I know there was a similar problem in another post. Perhaps this will help.
 

Attachments

Top