Behavior trees don't start for WebGL build

xxchester

New member
Hello, I have a really strange problem where my behavior trees are not loading for a WebGL build. I've spent a few days on this now and cannot get it to work on WebGL. Windows/Linux/Osx all work though.

When I load my scene, I load a pool enemies via this code:
C#:
GameObject enemyGO = Instantiate<GameObject>(Prefab, Container);
        enemyGO.GetComponent<AIWeapon>().ProjectilContainer = ProjectileContainer;
        Enemy enemy = enemyGO.GetComponent<Enemy>();
        enemy.Start();
        enemyGO.SetActive(false);

As you can see I immediately deactivate the GameObject that has the behavior tree. My behavior tree is configured to load on start:
1682546384095.png
Again this works on OS', it is only on WebGL that the trees are not loading when I "activate" (GO.SetActive(true)) an enemy. I have also tried turning on Log Task Changes and nothing is logged to the console. I am building a development build as well so there is logging to the console just nothing for Behavior Designer.

The whole tree is very basic, I added the log tasks trying to output anything to the console:
1682551777775.png

I thoughts or help would be greatly appreciated.
Thanks.
 
Last edited:
My guess is that a task is being stripped out. If you use the runtime source version you could have better results. If that still doesn't work you'll need to use a link.xml file to ensure Unity doesn't strip out any classes.

 
Hmm, I have a link.xml file like this:
Code:
<linker>
    <assembly fullname="BehaviorDesigner.Runtime" preserve="all" />
</linker>
But I still get the same result.

I should also mention, the stripping is set to Minimal as Disabled is not an option.

It's so weird, the whole game works other than the behavior trees. What do you mean use the runtime source? I am using what ships in the package manager, is there some other source code elsewhere?

Thanks.
 
You can download the runtime source from this page: opsive.com/downloads. This will likely fix the issue. If it still doesn't your linker will also need to include the BehaviorDesigner.Runtime.Tasks namespace.
 
Thanks for your response. I downloaded the source and imported it after removing the dlls for the runtime. However, when I start my game now I am facing these errors:
UnityException: get_isPlaying 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.
BehaviorDesigner.Runtime.BehaviorSource.CheckForSerialization (System.Boolean force, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at Assets/Behavior Designer/Runtime/BehaviorSource.cs:72)
BehaviorDesigner.Runtime.Behavior.CheckForSerialization (System.Boolean forceSerialization) (at Assets/Behavior Designer/Runtime/Behavior.cs:281)
BehaviorDesigner.Runtime.Behavior.CheckForSerialization () (at Assets/Behavior Designer/Runtime/Behavior.cs:274)
BehaviorDesigner.Runtime.BehaviorManager.LoadBehavior (BehaviorDesigner.Runtime.Behavior behavior, UnityEngine.GameObject behaviorGameObject, System.String gameObjectName, UnityEngine.Transform behaviorTransform) (at Assets/Behavior Designer/Runtime/BehaviorManager.cs:383)
BehaviorDesigner.Runtime.BehaviorManager+BehaviorThreadLoader.LoadBehavior () (at Assets/Behavior Designer/Runtime/BehaviorManager.cs:359)
System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) (at <3dd5df5ef4974f29afeb2d3ba227c5da>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <3dd5df5ef4974f29afeb2d3ba227c5da>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <3dd5df5ef4974f29afeb2d3ba227c5da>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) (at <3dd5df5ef4974f29afeb2d3ba227c5da>:0)
System.Threading.ThreadHelper.ThreadStart () (at <3dd5df5ef4974f29afeb2d3ba227c5da>:0)
UnityEngine.Application:get_isPlaying()
BehaviorDesigner.Runtime.BehaviorSource:CheckForSerialization(Boolean, BehaviorSource) (at Assets/Behavior Designer/Runtime/BehaviorSource.cs:72)
BehaviorDesigner.Runtime.Behavior:CheckForSerialization(Boolean) (at Assets/Behavior Designer/Runtime/Behavior.cs:281)
BehaviorDesigner.Runtime.Behavior:CheckForSerialization() (at Assets/Behavior Designer/Runtime/Behavior.cs:274)
BehaviorDesigner.Runtime.BehaviorManager:LoadBehavior(Behavior, GameObject, String, Transform) (at Assets/Behavior Designer/Runtime/BehaviorManager.cs:383)
BehaviorDesigner.Runtime.BehaviorThreadLoader:LoadBehavior() (at Assets/Behavior Designer/Runtime/BehaviorManager.cs:359)
System.Threading.ThreadHelper:ThreadStart()

Any idea's how to fix this?
 
Thanks. I just uploaded a runtime source fix. This is also included in version 1.7.5 going out now.
 
:cry: Thanks for fixing the c# error, however the original issue still remains. I'm not sure what to do, the behavior tree's all load and run in non-webgl builds.
 
Have you tried a fresh project with a simple behavior tree? That should help debug the issue. We have WebGL demos that use Behavior Designer and I haven't run into this. My guess is that something else is causing the tree not to start.
 
I'm able to reproduce it with a very simple project. In this project, when you are playing hit the #1 key on your keyboard to toggle the game object on and off. There are 2 error log statements, 1 stating that it is changing the activity of the object (not part of the behavior tree) and 2 it prints "we are here" every time the task is executed in the tree.

In the editor and windows build, it logs "we are here" every time the log task is executed. WebGL however only prints the 1st log statement, never executing the task in the tree.
Steps to reproduce:
  1. Go to Tools -> Build -> WebGL
  2. Zip up the contents of the WebGL in the build directory
  3. Upload to Itch.io
  4. Play the game
  5. Hit the #1 key to activate/deactivate the GameObject that has the behavior tree.
  6. Observe you only see error logs for the activation message, not the 2nd (We are here) from the tree.
 
Please do not upload the entire contents of Behavior Designer to the forum. Not everyone who reads the forum has a license to Behavior Designer.

With that said, I see the problem. I should have thought about that with the last message but you have asynchronous loading on when WebGL doesn't support separate threads. If you disable that checkbox for WebGL then it'll work. For the runtime source version I will add a warning about this to the next update.
 
Oh sorry about that, I didn't think about it.

Ah okay, I didn't realize WebGl doesn't support async loading but that would explain it. Thanks for looking into this for me and finding the root cause.
 
Top