"Can see object" task forgets its target after initial sighting

markrrrrrr

New member
I've got a behavior tree that, in its simplest form, is simply a sequence of "Can See Object" and "Move Towards." The object for "Can See" is defined by the Player tag, and "Move Towards" is the Player object. When I press play, the AI's "Can See" shows success and begins the "Move Towards" task. After that task completes (successfully), the "Can See" task is repeated and returns failure even with my Player capsule within the view cone. Moving my player capsule around, out of, and back into the view cone is fruitless: "Can See" is repeated thousands of times and fails each time.

I've tried setting the "Can See" task to find the Player game object directly (instead of by tag), but the result was the same. Adding debug comments to "Can See" code to display returnedObject.Value yield one line that shows "Player (UnityEngine.GameObject)" and thousands that show no target.

Ultimately what I'm trying to produce is a behavior that will pursue its target while the target is within sight and, if the target disappears (around a corner, for example) will go to the spot at which it last saw its target.

Any suggestions?
 
Using a simpler script, similar to your example script "Within Sight" (but with a raycast to rule out x-ray vision) works fine. My "Can See" script also sets a marker at the transform at which the AI last "saw" the Player, and I use that transform in my "Move To" task.

So my immediate problem is now solved, but I still wonder if my inability to get your "Can See Object" script to work is indicative of some misunderstanding that will plague me down the line.
 
Is Can See Object being reevaluated? If it isn't being reevaulated then only the first value will be used. The Ultimate Character Controller sample tree has similar behavior as what you are going for - take a look at this video for how it works:

 
I see that it works in the sample tree, but the simple tree I described fails as I described. For just a moment the AI "sees" the capsule with the player tag, then it looks for a null object. I added a debug line to your code -- no other changes -- and the log shows the player object as Player twice, followed by thousands of lines of "Player object:" followed by blank space.

When I use my simple "Can See Target" task in the same tree it works fine. I've tried quite a few different tree structures; they all work with my "Can See Target" task, they all lose track of the player using your "Can See Object" task.
 
Here is also a video that may help and shows Can See Object being reevaluated:

 
Yes, as I've said, "Can See Object" is being reevaluated within my tree, too. The problem is that after the first time, the AI resets the target tag from "Player" to null.
 
In the video above, "Can See" only has to find its target once, then it's done. I've never had any problem getting "Can See" to find its target once.

I've watched all your videos (other than some that discuss integration with assets I don't use). After encountering the problem I've described, I re-watched all the videos that seemed like they might help. I've read the documentation, and gone step by step through your examples. There's something going on that is not addressed by your videos and that, by process of elimination, seems to be related specifically to your "Can See Object" code. If the issue was my tree being faulty, substituting my simpler "Can See" code would not fix it. Substituting my simpler "Can See" code does fix it.

Maybe I'm missing something, but having me re-watch videos isn't helping me.
 
Top