Easier way to check if Object is Null.

DXWarlock

New member
Just getting into learning the ropes of BD, and for the life of me cannot find a logic in it to check if a saved object is null.
And have a very janky and 1/2 working simple Tree that is suppose to do simply the following:
If you see an enemy, flee. If while you are fleeing you see a new enemy update who you are fleeing from. If nothing else wander around.
Basically
to get a grasp of BD, attempting to have one AI in a maze do his best to avoid all enemy AI.

Only way I could work out after 2 hours of trying different options to get him to not randomly flee and throw an error of no target to flee from, was if you see an enemy interrupt wander, save the gameobject as a variable, then 'Get Speed" of that target and if target has speed, its not null and is a gameobject chasing you so turn on run and flee.
Which works sometimes..not sure why only sometimes. The "Draw line" draws lines from him to who is his target, and will have a line and he will not flee about 1/4 of the time even with 3-4 chasing him.

Also sometimes it will stop fleeing, the entire tree turns green and he slowly wanders around while being hit.

Any suggestions on how to clean this up and get ride of this buggy behavior? I'm sure its my novice grasp of BD and how particular conditionals work (or improper use of them).
Screenshot 2020-11-06 134321.jpg
 
Last edited:
If the debug line isn't being drawn then the Can See Object task isn't running. It looks like you are mixing conditional aborts and the the interruption tasks which will make things confusing when you are just getting started with the editor. I recommend first starting with conditional aborts and going from there.

At a high level you should be able to do something like this:

1604699797357.png

If you haven't seen it I also recommend that you take a look at the character controller integration tree docs as that gives a good overview for the flow of behavior trees.
 
That example does the same issue I run into now:
Code:
NullReferenceException: Object reference not set to an instance of an object
BehaviorDesigner.Runtime.Tasks.Movement.Flee.OnUpdate () (at Assets/Opsive/Behavior/Behavior Designer Movement/Scripts/Tasks/Flee.cs:33)
I cannot find a way to validate if target variable is not null before flee task executes, if no enemy is around near him right at start it stops with that error. Doesn't seem to be a "if != null" task I can use.

Something like this (with dummy conditional abort) :

5dEqID4.png

I even tried "Is Alive" which oddly returns true even if the target variable is "None (GameObject)".
 
Last edited:
If the target is null then you should not flee since there's no target to flee from. You can compare to null with the Compare Shared GameObject task.
 
Top