The BabylonJS Unity Toolkit is a toolkit that allows you to export a Unity project as a Babylon Project. It works by exporting your whole scene in the GLTF format and adding metadata.
It can be extremely convenient but it can be a bit hard to get started as the documentation is kinda lacking. Here I share a few things I’ve found out, and will keep adding more as I get more familiar with the topic.
Short build time
It takes 10-20 seconds to build your project. This is much faster than Unity for web (which takes several minutes at least). You also avoid all the time wasted by unity recompiling your C# (which is a major pain in more recent versions).
Only substractive lighting is supported for lightmaps
This is mentionned here in this video here: https://forum.babylonjs.com/t/require-extension-cvtools-babylon-mesh-is-not-available/17592/9
This means shadows from static objects will not be applied to moving objects. In Unity this is fixed by using light probes, but I am unsure as to how this is handled in the toolkit but I’ll try out soon.
The video also shows how to simplify meshes
The toolkit contains a mesh simplifier
This is REALLY neat if you’re using modular assets. This is mentionned in the video above: go to the Babylon geometry tools after selecting your object and run the mesh simplifier.
URP and HDRP shaders are not supported
They will be replaced by standard shaders, which will break your materials.
Do yourself a service, and stick to the standard rendering pipeline instead when using this toolkit. Your Unity project will also be a lot more responsive in Editor.
Materials don’t seem to be readily accessible from Mesh
I’ve tried to modify the material from a mesh at runtime, but I haven’t managed to access this material from the mesh. Instead, I’ve had to find the material by name from scene.materials.
I think the way to proceed for this is to toggle “instance meshes” in the unity toolkit and access the “instancedmesh” from your script component, but I haven’t tried it yet.
I’ve opened an issue as a request for information here: https://github.com/BabylonJS/UnityExporter/issues/36
Register ScriptComponents on mesh object to access them
I wanted to access an object’s Controller (a user-created script component) after detecting a mesh by raycasting, but related methods (FindScriptComponent or something similar) either didn’t find anything or required lookup by class name in string, which I thought might be problematic in case of inheritance.
In this case, I decided to go another way: a script component has access to a transform mesh and, as it turns out, the mesh accessed by raycasting is the transform mesh so we can look up a property by name.
In my case, I set a “controller” script component as the “controller” property of the mesh and was able to access it through raycasting.
Exporting mecanim animations is mostly well supported, with exceptions
I was trying to export Unity chan from the following asset: https://assetstore.unity.com/packages/3d/animations/haon-sd-series-bundle-84992
The mesh does get exported but some animations seem to be broken, with unity chan being stuck in T-Pose.
I think the issue is likely due to the model being modular: face is seperated from body etc, so I guess the current workflow for Mecanim export is broken. I guess this could be solved by merging the different parts. There are some skinned mesh mergers on the asset store, but I haven’t tried them yet. I’ve tried a few scripts I’ve found online, but the results were far from great.
That’s all for now, I’m still getting used to the whole thing but I thought the toolkit is great work and is pretty neat. I’ll keep posting things as I figure them out if I think it’s useful to know.