Help with Replicating Tutorial Behaviour Tree

Nads

New member
Hi,

I own behaviour tree and movement pack, but i dont own any Ultimate Controller packs.

Ive been trying to replicate your enemy behaviour tree tutorial from here

As im missing the Character Controller, i cant run the demo scene cause im getting errors. However, in my project ive replicated your tree but instead of using the Start Stop Use and Abilities (have no idea what these are meant to do?) ive just replaced these nodes with logs for now.

With this replication and a few modifications to the tree, i have the enemy zombie patrolling between checkpoints okay. However, he never sees my player character?!

Im unsure how the TARGET field works, in Unity inspector i add my Player Object as the Target in the Behaviour Tree variables. But right at the start of the tree, you have a Set Reset Target? Which removes my player from this variable. Also in your nodes CAN SEE OBJECT, Target Object is always set to None, so how does it know who its looking for (ie. the player in my case)?

I would be really thankful if you could please help me solve this issue im having?

I have attached screenshots of my tree.

Thanks.

1.png


2.png


3.png


ZombieScreenshot1.png
 
Instead of starting with a tree that doesn't work I recommend starting basic and slowly adding from there. That's how the UCC tree was created and it's a lot easier to get things going.

Have you seen the Behavior Tree Basics videos? This one in particular uses Can See Object:


The CTF and RTS sample projects are also good ones to get going with:

 
Okay thanks Justin.

Yes I did create simple trees already using your videos such as the Can See Object. I haven’t had a look at the CTF or RTS samples yet so will definitely check those out aswell.

But if you could also please just explain in your ultimate controller tutorial how does the target get assigned to the player? And why does it need to be reset right at the start of the tree? Don’t you need to assign the target variable manually in the unity inspector before running the tree?

Thanks
 
The Can See Object will assign the Target variable

Sorry what i meant is how does the Can See Object know that its looking only for the player Target? Do you use a Tag or something else in that Ultimate Character Controller Tutorial Scene, cause i cant see anything to do with this, thanks.
 
Last edited:
Sorry what i meant is how does the Can See Object know that its looking only for the player Target? Do you use a Tag or something else in that Ultimate Character Controller Tutorial Scene, cause i cant see anything to do with this, thanks.
Can See Object will only search for objects with the Character layer.
 
Can See Object will only search for objects with the Character layer.
Ah i see, one thing though, is this an automatic feature of the Can See Object or needs to be assigned? Because i dont see it assigned anywhere in the example tutorial. Should it be like this?
I have my player on the Player layer, do i need to manually assign this in the node?

I watched both of your videos linked above (can see object) and CTF video, but in the first video nothing was described or shown with regards to the player as target, and in the CTF video it was assigned manually as a target which is not done in the Ultimate Controller Tutorial project, i guess thats whats confusing me.
 
Ah i see, one thing though, is this an automatic feature of the Can See Object or needs to be assigned? Because i dont see it assigned anywhere in the example tutorial. Should it be like this?
I have my player on the Player layer, do i need to manually assign this in the node?
You can set the layer that the Can See Object task searches for, and then assign the found object to the Returned Object field.
 
You can set the layer that the Can See Object task searches for, and then assign the found object to the Returned Object field.
Thanks so much Justin, its working now, hooray!!! I think the integration project for ultimate controller probably got messed up and missed a few things as it was missing the Ultimate Character Controller pack, and in turn the scripts, layers, tags etc are all omitted out.

But assigning the tag makes it work correctly.

Just a few tips if you could share please:

1. What is the "Start Stop Use" for? What was the purpose of that node in your example?
2. What is the "Start Stop Ability" for? What was the purpose of that node in your example?

3. How do i make an animation play when i get to certain points in the tree? For example, when i get to the Can See Object Node (Attack the target for as long as the target is within sight.) You had Start Stop Ability and Use Nodes and then a Wait node for cooldown. Would i place an animation node instead of these Ability and Use nodes? or would i have to do something else?

4. As a general rule for game dev in general i guess, Should the behaviour tree for enemies be created first on a plain object (like a cube), or should the actual character be placed first and then animations added to the character and then the AI added?

Thanks for your help!
 
1. What is the "Start Stop Use" for? What was the purpose of that node in your example?
2. What is the "Start Stop Ability" for? What was the purpose of that node in your example?
Those are specific to the Ultimate Character Controller but this page has an overview: https://opsive.com/support/documentation/behavior-designer/integrations/opsive-character-controllers.

3. How do i make an animation play when i get to certain points in the tree? For example, when i get to the Can See Object Node (Attack the target for as long as the target is within sight.) You had Start Stop Ability and Use Nodes and then a Wait node for cooldown. Would i place an animation node instead of these Ability and Use nodes? or would i have to do something else?
This page explains that aspect: https://opsive.com/support/documentation/behavior-designer/syncing-animations/

4. As a general rule for game dev in general i guess, Should the behaviour tree for enemies be created first on a plain object (like a cube), or should the actual character be placed first and then animations added to the character and then the AI added?
I would create the AI on the actual character because chances are the AI will need to directly interact with that character (such as for firing a weapon).
 
This is the reason why we need up to date tutorials and also a tutorial with an animated character. The examples alone are not enough for some people like me because it doesn't tell you why is it like that. I absolutely hate them tutorials that are only capsules and cubes because I had questions on but how does the animated character move though. When you have the controller it is easier to know how the AI moves. My point is what behavior designer lacks in is proper tutorials. It is good but ICE Creature Control was better ONLY because there were heaps of good tutorials. And also people say you don't need to know code but that is untrue unless you own playmaker. Sorry for my rant but most great assets lack good tutorials which are a shame.
 
This is the reason why we need up to date tutorials and also a tutorial with an animated character. The examples alone are not enough for some people like me because it doesn't tell you why is it like that. I absolutely hate them tutorials that are only capsules and cubes because I had questions on but how does the animated character move though. When you have the controller it is easier to know how the AI moves. My point is what behavior designer lacks in is proper tutorials. It is good but ICE Creature Control was better ONLY because there were heaps of good tutorials. And also people say you don't need to know code but that is untrue unless you own playmaker. Sorry for my rant but most great assets lack good tutorials which are a shame.

i think you might be right, there's not enough tutorials on behaviour tree, and the tutorials that are there are way to basic which is a good start but we really need more advanced real world tutorials, at the moment I've only come across one which is the tutorial for the ultimate character controller but even that doesn't really tell us about using with animations etc.. ive paused work currently on the AI while i get my enemy zombie models with animation setup after that then i plan on going back to completing the AI tree, but when i do go back I'm gonna have to spend quite a bit of time trying to figure out how to play those animations or about writing custom tree nodes that activate animations as currently im not sure how to do it. I had a quick look at the document Justin linked above for syncing animations but still wasn't very clear from that. I will have to check out a tutorial project that makes use of it to know what to do i guess.
 
One of the main issues with animation syncing is that it requires an external character controller in order to do properly. You can definitely set the animator properties within the behavior tree, but that becomes unwieldy as the size of your tree grows. Did you see the link to the cached MecWarriors article? This is an extremely good article to start with in terms of how to properly sync your animations - with this method you don't need to worry about the animations at all within your tree.
 
One of the main issues with animation syncing is that it requires an external character controller in order to do properly. You can definitely set the animator properties within the behavior tree, but that becomes unwieldy as the size of your tree grows. Did you see the link to the cached MecWarriors article? This is an extremely good article to start with in terms of how to properly sync your animations - with this method you don't need to worry about the animations at all within your tree.

I am doing a vr game using steamVR and VRTK, hence i cant really use any of your character controller assets.

I had a quick glance at the MecWarriors article, but as i hadn't started this part yet, i haven't run into the animation issue as such yet. But it will happen soon enough.

But if we have to use a old cached article from 2015 to get your asset working with animations, isn't that a failure of the asset? Not asking this in a negative way, but just genuinely interested in hearing about this. If your asset is reliant on working with methods mentioned in MecWarriors article, then you definitely should do a video tutorial on implementing these methods with your asset. It would make it much easier for people and also it would be up to date, as the 2015 article might not be up to date anymore.
 
Hey Justin,

its me again, okay so i have my zombie enemy character created now with animations. I have used Animator and added a blend tree with various animations for idle, walking, running, turning on the spot, walk turning and run turning. I also have a separate Attack Layer, which has 3 different types of attacks that the zombie can do.

In Animator parameters, i have created Triggers for Attack1, Attack2, Attack3, and a float for Speed. Still unsure if i require another state Int parameter called MoveState or if i should be able to just use Speed parameter to move the enemy around.

Ive read up the MecWarriors article, which definitely helped me understand some stuff. However, im still unsure how i should use Behaviour Tree AI with this CharNav Script?!

For example, in the CharNav script he used the following code to see if the enemy was told to go somewhere via mouse click:

C#:
void Update ()
{
    //character walks if there is a navigation path set, idle all other times
    if (navAgent.hasPath)
        moveState = MoveState.Walking;
    else
        moveState = MoveState.Idle;
    //send move state info to animator controller
    animController.SetInteger("MoveState", (int)moveState);
}

But my zombie uses Behaviour Designer to Seek the enemy, so how can i get that to work? Will Behaviour Designer set "if (navAgent.hasPath)" to true as soon as the zombie starts to move, be it seeking, wandering etc... or do i need to call some variable in my code to get the status from the behaviour tree?

Lastly, how can i use my attack triggers that have been setup in my Animator? Do i need to add a special node in Behaviour tree that calls the Attack1, Attack2 or Attack3 trigger parameters from Animator?

Thanks.
 
But my zombie uses Behaviour Designer to Seek the enemy, so how can i get that to work? Will Behaviour Designer set "if (navAgent.hasPath)" to true as soon as the zombie starts to move, be it seeking, wandering etc... or do i need to call some variable in my code to get the status from the behaviour tree?
Behavior Designer won't set that variable directly, but if you use the Seek task then Seek will set the destination of the NavMeshAgent and at that point the hasPath variable becomes true.

Lastly, how can i use my attack triggers that have been setup in my Animator? Do i need to add a special node in Behaviour tree that calls the Attack1, Attack2 or Attack3 trigger parameters from Animator?
For the Ultimate Character Controller I have a task called Try Use Item (which is basically attack) and that first checks to ensure the weapon can attack, and then if it can it'll then set a parameter within the animator. This prevents Behavior Designer from needing to know any structure of the animator.

For your case to get started you could create a task which calls on your custom character controller to attack and then your custom character controller sets the parameter.
 
Behavior Designer won't set that variable directly, but if you use the Seek task then Seek will set the destination of the NavMeshAgent and at that point the hasPath variable becomes true.


For the Ultimate Character Controller I have a task called Try Use Item (which is basically attack) and that first checks to ensure the weapon can attack, and then if it can it'll then set a parameter within the animator. This prevents Behavior Designer from needing to know any structure of the animator.

For your case to get started you could create a task which calls on your custom character controller to attack and then your custom character controller sets the parameter.

Thanks i will try the first part out and hopefully it will work.

As for the attack, can you please elaborate on creating a custom task cause i dont have UCC to check the USE ITEM node out.

Are you saying that my custom task node should call my character class (the class where im checking for the NavMesh destination) and setting the character speed etc... and from my custom node i can reference the animator and set its attack trigger paramater? or do you mean something else?

thanks
 
Are you saying that my custom task node should call my character class (the class where im checking for the NavMesh destination) and setting the character speed etc... and from my custom node i can reference the animator and set its attack trigger paramater?
That's right. Your custom task should for example call the Attack method on your character class. This Attack method then sets the parameters on the animator that it needs in order to attack.
 
Thanks Justin, but I’m afraid I have some very beginner questions.

How can I access my controller class from the custom task? My controller class is just called AINavigator.

I’m having some issues with my enemy character (ie. the zombie), it’s set as Root Motion, has a RigidBody, isGravity is on. I also have for now just added a capsule collider to the whole zombie object. However the zombie just floats in the air a few centimetres off the floor. Even if I start the scene with placing him well above the floor he never drops to the floor?! Any idea why that’s happening? I also tried selecting isKinetic but that didn’t help.

Also when the AI collided with anything such as the player that it’s seeking, he just goes right through my collider and goes to the centre of my player object before stopping, in the behaviour I have selected a large value for the AI to stop at when he reaches his target but he completely ignores this.

Any help with this stuff please Justin?

Thanks
 
Top