Null pointer exception when Upgrading to 1.6.2

funbitesgames

New member
After I solved all import issues, the behavior tree is not showing any errors, but when I play I get the following Null Exception:

Code:
NullReferenceException: Object reference not set to an instance of an object
BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
BehaviorDesigner.Runtime.BehaviorManager.EnableBehavior (BehaviorDesigner.Runtime.Behavior behavior) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
BehaviorDesigner.Runtime.Behavior.EnableBehavior () (at <8273d6b105784beab3b1f76a8d030c0c>:0)
Josh.AI.BehaviorTreeConnector.EnableBehavior () (at Assets/JoshData/Scripts/Behaviors/BehaviorTreeConnector.cs:82)
 

Justin

Administrator
Staff member
What version did you upgrade from? Are you able to reproduce it within a fresh project so I can take a look?
 

funbitesgames

New member
I upgraded from 1.6.1 and I'm using Unity 2018.3.12f.

How could I reproduce it in a fresh project? I create an empty project and add my custom actions, conditions and external behaviour trees and upgrade it? That's gonna be a lot of work, besides my custom actions makes reference to my game code.
 

funbitesgames

New member
I did a process of removing nodes to find where the bug happens.
It happens in the External Behavior Tree Node when I set a variable of a custom type that I made:

C#:
namespace Josh.AI {
    [System.Serializable]
    public class SharedTargetPositionFromOpponentList : SharedVariable<List<TargetPositionFromOpponent>> {
        public static implicit operator SharedTargetPositionFromOpponentList(List<TargetPositionFromOpponent> value)
            { return new SharedTargetPositionFromOpponentList { mValue = value }; }
    }
}
behaviordesigner.png
 

funbitesgames

New member
Thanks for provinding the source code.
I debug here and everything is fine until it reaches these lines, starting at 523 of BehaviorManager.cs
C#:
sharedVariable = (overrideField.Value as NamedVariable).value;
sharedVariable.Name = (overrideField.Value as NamedVariable).name;
if (sharedVariable.IsGlobal) {
    sharedVariable = GlobalVariables.Instance.GetVariable(sharedVariable.Name);
 } else if (sharedVariable.IsShared) {
    sharedVariable = behaviorTree.behavior.GetVariable(sharedVariable.Name);
}
The shared variables in the first line is the right reference and IsShared is true. When the code check if it is IsShared, it returns a null reference. I think the variable "MovePositions" is not registred in the behaviorTree. The error will occur at line 539 when it tries to add the sharedVariable to the behaviorTree, but it's null.
I did a test, and renamed the NearPositions variable to MovePositions and it worked.
So the problem maybe is because he is not Adding MovePositions to the source behavior tree. You do that at line 471. Or IsShared should be false and it's true because of serialization issue due to the upgrade.
I deleted the variable in the reference behavior tree and created another variable, but the problem persists. It used to work in 1.6.1
 

Justin

Administrator
Staff member
Please do not include Behavior Designer in packages as this is a public forum and not everyone has a license to Behavior Designer.

Thanks for the repro scene though. I'm debugging it to come up with a proper fix - where is NearPositions defined? If the variable is shared it should be contained within the behavior tree's variable list and for some reason it's not in this case.
 

funbitesgames

New member
Sorry about that. I remember to provide my purchase ID to join the forum, so I thought every member had behavior designer.

I have 2 behavior trees: Lizard and MoveToPosition. The Lizard refers to the enemy that have a NearPositions (relative to that enemy). The MoveToPosition is a generic move to behavior. So NearPositions is defined in the Lizard Behavior tree.

Do you want me to make another package without behavior designer. I could reproduce the error only with SharedGameObject.
 

Justin

Administrator
Staff member
Thanks - I see it now. From the block of code that you pasted a few days ago if you remove:

Code:
sharedVariable.Name = (overrideField.Value as NamedVariable).name;
It should then work.
 

funbitesgames

New member
Not working. The reference to the shared variable seemed to work, but the fixed value SetValue resulted in very weird behavior.
 
Last edited:

funbitesgames

New member
I solved the issue by not using a SharedVariable. In my case I can set the fixed value in the Behavior Tree Reference task and it works. So, don't worry, take your time to make a proper fix.
 

Justin

Administrator
Staff member
What was the weird behavior that you are experiencing? When I ran your repro scene both GO2 and GO3 were activated.
 

funbitesgames

New member
It works for this specific case, but stop working for other cases in my project. I think it creates a issue with variable overrides that are not shared variables.
 
Top