Find doesn't seem to populate variable for other tasks

Rick

New member
Just starting out and I found this page (https://opsive.com/support/documentation/behavior-designer/referencing-scene-objects/) about using Find to populate a variable that other tasks can use. I have a behavior tree on an enemy. While Find returns success the other task, Within Distance, never does. If I change Within Distance to use a tag instead then it works so it seems like the variable idea with Find isn't working. I don't wish to do this in code. What kind of debugging can I do to see why Find returns success, I assume this means it was able to find the object in question and set it, but why Within Distance fails.



Something I noticed when running is I get this error right away:

The behavior "Behavior" on GameObject "Player(Clone)" contains no root task. This behavior will be disabled.
UnityEngine.Debug:LogError(Object)
BehaviorDesigner.Runtime.BehaviorManager:LoadBehaviorComplete(Behavior, BehaviorTree)
BehaviorDesigner.Runtime.BehaviorManager:EnableBehavior(Behavior)
BehaviorDesigner.Runtime.Behavior:EnableBehavior()
BehaviorDesigner.Runtime.Behavior:Start()


However, the "Player" game object is the thing we're Finding on the enemy's behavior tree. The Player doesn't have a behavior tree and I wouldn't want the player to have the behavior tree so not sure why I'm getting this error message.
 
That error looks like you accidentally added a behavior tree to the player.

The Find task uses GameObject.Find so it'll follow the rules based on this page.
 
My Player did have an empty BT on it so removed that and that fixed that issue.

I'm not sure what you're trying to get at with the docs page of GameObject.Find(). In the BT the Find returns success so it seems like it finds it, but the next WithinDistance task never returns success when I had Find put that player GameObject into a variable and have WithinDistance use that variable as the target object. So while Find does find the object it seems like it doesn't put it in the variable or WithinDistance isn't using the variable correctly? When I use Target Tag on WithinDIstance then it works and that's fine for this, but I wanted to figure out using Find and variables in BT's as well as that'll be useful I can see.

Really the reason I need this is because of the flee task (I have the movement add-on) because that needs the game object to flee from and since that variable idea of Find doesn't seem to populate the variable correctly even though it returns success the flee task has the navagent just moves forward and runs into a wall. Since that variable of the game object doesn't seem to be working I think flee doesn't work right.
 
Last edited:
The Find task will always return success, though I like the idea of only returning success if it found an object.

Can you output the value of storeValue.Value within Find.OnUpdate to see if it found the object that you are looking for? Beyond that you'll need to make sure you are using the same SharedVariable for both Find and WithinDistance/Flee.
 
Oh, yeah I figured it would do that. Forgot I can just check out the code. Found the issue and it's dumb of course :). Unity appends (Clone) to the end of the name so I had to add that in the Find so Player(Clone) not just clone. My bad :) Thanks for the patience and help!
 
Top