Whole behaviour tree disappeared on editor , "KeyNotFoundException: The given key was not present in the dictionary." shows on the console

Desertfeng

New member
I tried to make a simple template of an external behaviour tree, so I could quickly make some similar external behaviour trees.
What I did was duplicate a gameobject attached behaviour tree several times, and I also made a prefab of that template. i can't remember clearly what i did because this is my first time using behaviour designer, so I explored some setting, changed some variable name , suddenly the whole behaviour tree disappeared and i got some error message. here's the screenshot, can i get some help? thanks.
 

Attachments

  • 1.png
    1.png
    151.5 KB · Views: 4
  • 2.png
    2.png
    116.8 KB · Views: 4
Are you able to tell me how to reproduce the error? I don't see the call stack so I'm not sure what part of code is triggering that error.
 
Are you able to tell me how to reproduce the error? I don't see the call stack so I'm not sure what part of code is triggering that error.
Hi Justin, I tried to reproduce it but i failed. but theres one thing could be help, before the error happened I noticed there are two variables (my custom sharedvariable) with the same name displayed on the inspector. it pumps some error messge through unity console at beginning, then i delete one of them. Suddenly the entire behavior tree disappears.
Do you have any clues on what could cause this error (like how to create two variables with the same name which is not allowed in normal situations) so that i can try to reproduce it or avoid it.
And, in my case, is there a way I could recover it? (like manual edit some json file or something) , or i just permanently lose my work? I'm kind of worried if that happened in the later period of development.
 
Last edited:
I can say that this is not a common exception so hopefully you won't run into it again. If it does happen again can you copy the stack trace so I can see where it is coming from? If you are using JSON serialization you should be able to recover it - if you post your JSON string I should be able to see what is wrong.
 
where can i get the Json string?
I can say that this is not a common exception so hopefully you won't run into it again. If it does happen again can you copy the stack trace so I can see where it is coming from? If you are using JSON serialization you should be able to recover it - if you post your JSON string I should be able to see what is wrong.
 
I can say that this is not a common exception so hopefully you won't run into it again. If it does happen again can you copy the stack trace so I can see where it is coming from? If you are using JSON serialization you should be able to recover it - if you post your JSON string I should be able to see what is wrong.
Hi Justin, I have figured out how to reproduce this error, the problem may be caused by my custom shared variables which have cycle dependence.

Step 1: Create an empty game object attached behavior tree
Step 2: Create a one shared variable V and one task T(they hold references to each other), see the screenshot
Step 3: Add a variable of V on the behavior tree editor

Then the entire behavior tree will disappear and crash. here is the stack trace

KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <fb001e01371b4adca20013e0ac763896>:0)
BehaviorDesigner.Runtime.JSONDeserialization.Load (BehaviorDesigner.Runtime.TaskSerializationData taskData, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorSource.CheckForSerialization (System.Boolean force, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Editor.GraphDesigner.Load (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, System.Boolean loadPrevBehavior, UnityEngine.Vector2 nodePosition) (at <c30b522bd9d44078a580374210656c3e>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.LoadBehavior (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, System.Boolean loadPrevBehavior, System.Boolean inspectorLoad) (at <c30b522bd9d44078a580374210656c3e>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.UpdateTree (System.Boolean firstLoad) (at <c30b522bd9d44078a580374210656c3e>:0)
BehaviorDesigner.Editor.BehaviorDesignerWindow.OnSelectionChange () (at <c30b522bd9d44078a580374210656c3e>:0)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <fb001e01371b4adca20013e0ac763896>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <fb001e01371b4adca20013e0ac763896>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <fb001e01371b4adca20013e0ac763896>:0)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at <bccb16a88ec4456dbf07978c418f407b>:0)
UnityEditor.HostView.Invoke (System.String methodName) (at <bccb16a88ec4456dbf07978c418f407b>:0)
UnityEditor.HostView.OnSelectionChange () (at <bccb16a88ec4456dbf07978c418f407b>:0)

I may avoid this in the future but I still want to know how to recover it if do it by accident, because it will lose all my work. it is scary.
"If you are using JSON serialization you should be able to recover it - if you post your JSON string I should be able to see what is wrong."
-- I don't understand what you mean, I didn't use any serialization things, I assume your team uses JSON to store the data of a behavior tree, but I didn't find the file location of that.
 

Attachments

  • 3.png
    3.png
    31.1 KB · Views: 7
I'm glad that you were able to find a repro. Can you post the shared variable code so it's easier to copy? I'll send you a PM with a fixed version as soon as I fix it.
 
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BehaviorDesigner.Runtime.Tasks;
using BehaviorDesigner.Runtime;
public class VAR
{
public string testName;
public InteruptByStrategy interrupt;
}
[System.Serializable]
public class SharedTestVAR : SharedVariable<VAR>
{
public static implicit operator SharedTestVAR(VAR value) { return new SharedTestVAR(value) { Value = value }; }
public SharedTestVAR(VAR strategy)
{
this.Value = strategy;
}
public SharedTestVAR()
{
}
}
public class InteruptByStrategy : Interrupt
{
public SharedTestVAR TestVar;
public bool isHoldingStrategy(VAR _testvar)
{
return TestVar.Value == _testvar;
}
}
I'm glad that you were able to find a repro. Can you post the shared variable code so it's easier to copy? I'll send you a PM with a fixed version as soon as I fix it.
 
Thanks, I was able to reproduce it and fixed it. I'll send you a PM with the new version.
 
Top