We get the following error when trying to enable Asynchronous Load on our BehaviorTree component:
We were really hoping this would be a simple solve to our frame rate spikes when spawning our characters (takes anywhere from 5-8ms), but it appears it's just not natively supported with v1.7.11 of BehaviorDesigner.
Code:
UnityException: GetComponent can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.GameObject.GetComponent (System.Type type) (at <575c8d5d94a9444f82eba927ac72f8df>:0)
BehaviorDesigner.Runtime.SharedVariable`1[T].InitializePropertyMapping (BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <eed7427f31054735b37e5687df728aa5>:0)
BehaviorDesigner.Runtime.JSONDeserialization.DeserializeSharedVariable (System.Collections.Generic.Dictionary`2[TKey,TValue] dict, BehaviorDesigner.Runtime.IVariableSource variableSource, System.Boolean fromSource, System.Collections.Generic.List`1[T] unityObjects) (at <eed7427f31054735b37e5687df728aa5>:0)
BehaviorDesigner.Runtime.JSONDeserialization.DeserializeVariables (BehaviorDesigner.Runtime.IVariableSource variableSource, System.Collections.Generic.Dictionary`2[TKey,TValue] dict, System.Collections.Generic.List`1[T] unityObjects) (at <eed7427f31054735b37e5687df728aa5>:0)
BehaviorDesigner.Runtime.JSONDeserialization.Load (BehaviorDesigner.Runtime.TaskSerializationData taskData, BehaviorDesigner.Runtime.BehaviorSource behaviorSource, System.Boolean loadTasks) (at <eed7427f31054735b37e5687df728aa5>:0)
BehaviorDesigner.Runtime.BehaviorSource.CheckForSerialization (System.Boolean force, BehaviorDesigner.Runtime.BehaviorSource behaviorSource, System.Boolean isPlaying) (at <eed7427f31054735b37e5687df728aa5>:0)
BehaviorDesigner.Runtime.Behavior.CheckForSerialization (System.Boolean forceSerialization, System.Boolean isPlaying) (at <eed7427f31054735b37e5687df728aa5>:0)
BehaviorDesigner.Runtime.BehaviorManager.LoadBehavior (BehaviorDesigner.Runtime.Behavior behavior, UnityEngine.GameObject behaviorGameObject, System.String gameObjectName, UnityEngine.Transform behaviorTransform) (at <eed7427f31054735b37e5687df728aa5>:0)
BehaviorDesigner.Runtime.BehaviorManager+BehaviorThreadLoader.LoadBehavior () (at <eed7427f31054735b37e5687df728aa5>:0)
System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) (at <e19fb1224222436ca0871ff12e7fb293>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <e19fb1224222436ca0871ff12e7fb293>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <e19fb1224222436ca0871ff12e7fb293>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) (at <e19fb1224222436ca0871ff12e7fb293>:0)
System.Threading.ThreadHelper.ThreadStart () (at <e19fb1224222436ca0871ff12e7fb293>:0)
UnityEngine.GameObject:GetComponent(Type)
BehaviorDesigner.Runtime.SharedVariable`1:InitializePropertyMapping(BehaviorSource)
BehaviorDesigner.Runtime.JSONDeserialization:DeserializeSharedVariable(Dictionary`2, IVariableSource, Boolean, List`1)
BehaviorDesigner.Runtime.JSONDeserialization:DeserializeVariables(IVariableSource, Dictionary`2, List`1)
BehaviorDesigner.Runtime.JSONDeserialization:Load(TaskSerializationData, BehaviorSource, Boolean)
BehaviorDesigner.Runtime.BehaviorSource:CheckForSerialization(Boolean, BehaviorSource, Boolean)
BehaviorDesigner.Runtime.Behavior:CheckForSerialization(Boolean, Boolean)
BehaviorDesigner.Runtime.BehaviorManager:LoadBehavior(Behavior, GameObject, String, Transform)
BehaviorDesigner.Runtime.BehaviorThreadLoader:LoadBehavior()
System.Threading.ThreadHelper:ThreadStart()
We were really hoping this would be a simple solve to our frame rate spikes when spawning our characters (takes anywhere from 5-8ms), but it appears it's just not natively supported with v1.7.11 of BehaviorDesigner.