I’ve upgraded to 2.6.3 yesterday and we now have lots of new warnings about duplicate GlobalBlackboard instances in our scenes, even though there is just one global blackboard! But it’s a prefab instance, so the same GlobalBlackboard lives a “silent” live in the asset database, too.
I guess I could track it down to the change of the global blackboard registering behaviour. In 2.6.2 they registered themselves in OnEnable, now they do it in Awake. The catch is that Awake will be called for prefabs, but OnEnable will not, so this explains why we’re getting this error now.
Edit: Looks like OnEnable will also be called for Prefabs (Maybe a 2017 thing?)
Edit2: Actually, I was wrong all the time. It’s the OnValidate() implementation 🙂
Repro:
– Create a new scene
– Add a GlobalBlackboard to it
– Store the GameObject with the GlobalBlackboard as a prefab
– Close/Reopen scene
– Observe “Duplicate GlobalBlackboard” error.
I could hotfix it by changing the condition in OnValidate from !allGlobals.Contains(this)
to UnityEditor.PrefabUtility.GetPrefabType(this) != UnityEditor.PrefabType.Prefab && !allGlobals.Contains(this)
And gameObject.scene.IsValid() && !allGlobals.Contains(this)
would also work.
I’ve recently been reported this problem by someone else too 🙂
I fixed this by adding this piece of code at the start of both OnEnable and OnValidate methods of GlobalBlackboard.cs:
1
2
3
4
5
6
7
#if UNITY_EDITOR
if(UnityEditor.EditorUtility.IsPersistent(this)){
return;
}
#endif
This is very similar to what you have done of course 🙂