Another Null Ref exception in 1.6.2

Slavo

New member
Hello, I wanted to upgrade the BD version from 1.6.1 to 1.6.2, but our trees have null ref exception in the new version :-o

The exception is when we are Enabling a BD Tree with a subtree in BTReference node. The subtree has a variable called "Position". The parent tree does not contain variable of the same name. The variable in the child tree is linked to a different variable in the parent tree through the variables property of the BTReference node in the tree editor.

The nullRef is in BehaviorManager - AddToTaskList line 541:
behaviorTree.behavior.SetVariable(sharedVariable.Name, sharedVariable);
the shared variable is null, ant the null if propagated from line 528

if (sharedVariable.IsShared) {
sharedVariable = behaviorTree.behavior.GetVariable(sharedVariable.Name); // this returns null
}
 
I believe that I just fixed this yesterday. Since you have the runtime source downloaded try removing the following lines after line 542:

Code:
                                                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);
                                                }
 
Hi Justin,

I'm getting the same null ref (on line 541 BehaviorManager) after upgrading from 1.6.1 to 1.6.2.

After removing the lines you suggest (on BehaviourManager.cs line 524 TO 529), i'm starting getting another error :

Error: Unable to set SharedVariable - the variable type BehaviorDesigner.Runtime.SharedBool does not match the existing type BehaviorDesigner.Runtime.SharedFloat

When i tryied to print the name of origSharedVariable.Name AND sharedVariable.Name both are EMPTY.

I Didn't change any thing on my BTrees so they are simply broken after upgrade...

Thank you for your help

PS: There is a way to rollback to the 1.6.1 version ?
 
Hello, the same for me as for Amynox, but the behavior will load up now and run without any runtime errors, I am not sure if the behavior is loaded fully ok (it is quite big)
Error: Unable to set SharedVariable - the variable type BehaviorDesigner.Runtime.SharedInt does not match the existing type BehaviorDesigner.Runtime.SharedBool
the callstack leads to the same line (541) in the behavior manager source
 
Can you send me a repro scene so I can take a closer look at this? I'd like to get it fixed once and for all.
 
Hello, I was able to reproduce the issues in this parent and child tree. (both before and after the first fix)
 

Attachments

  • Resources.zip
    3 KB · Views: 1
Thank you. I'll create a unit test to ensure this doesn't happen again.

In BehaviorManager.cs replace

Code:
                                        TaskAddData.OverrideFieldValue overrideField;
                                        if (data.overrideFields.TryGetValue(loadedBehaviorSource.Variables[j].Name, out overrideField)) {
                                            if (overrideField.Value is SharedVariable) {
                                                sharedVariable = overrideField.Value as SharedVariable;
                                            } else if (overrideField.Value is NamedVariable) {
                                                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);
                                                }
                                            } else if (overrideField.Value is GenericVariable) {
                                                sharedVariable = (overrideField.Value as GenericVariable).value;
                                                if (sharedVariable.IsGlobal) {
                                                    sharedVariable = GlobalVariables.Instance.GetVariable(sharedVariable.Name);
                                                } else if (sharedVariable.IsShared) {
                                                    sharedVariable = behaviorTree.behavior.GetVariable(sharedVariable.Name);
                                                }
                                            }
                                        } else {
                                            sharedVariable = loadedBehaviorSource.Variables[j];
                                        }

with:

Code:
                                        TaskAddData.OverrideFieldValue overrideField;
                                        if (data.overrideFields.TryGetValue(loadedBehaviorSource.Variables[j].Name, out overrideField)) {
                                            if (overrideField.Value is SharedVariable) {
                                                sharedVariable = overrideField.Value as SharedVariable;
                                            } else if (overrideField.Value is NamedVariable) {
                                                sharedVariable = (overrideField.Value as NamedVariable).value;
                                                behaviorTree.behavior.GetBehaviorSource().UpdateVariableName(sharedVariable, (overrideField.Value as NamedVariable).name);
                                                if (sharedVariable.IsGlobal) {
                                                    sharedVariable = GlobalVariables.Instance.GetVariable(sharedVariable.Name);
                                                } else if (sharedVariable.IsShared && (behaviorTree.behavior.GetVariable(sharedVariable.Name) != null)) {
                                                    sharedVariable = behaviorTree.behavior.GetVariable(sharedVariable.Name);
                                                }
                                            } else if (overrideField.Value is GenericVariable) {
                                                sharedVariable = (overrideField.Value as GenericVariable).value;
                                                if (sharedVariable.IsGlobal) {
                                                    sharedVariable = GlobalVariables.Instance.GetVariable(sharedVariable.Name);
                                                } else if (sharedVariable.IsShared && (behaviorTree.behavior.GetVariable(sharedVariable.Name) != null)) {
                                                    sharedVariable = behaviorTree.behavior.GetVariable(sharedVariable.Name);
                                                }
                                            }
                                        } else {
                                            sharedVariable = loadedBehaviorSource.Variables[j];
                                        }
 
Top