Why are loader plugins recreated every time?

Hey, I just lost quite some time trying to debug why every time I load some asset, the properties I previously set on the loader plugin were lost.

I want to set loadAllMaterials for the GLTFFileLoader. I was expecting that once I set this, every subsequent load call will make use of it, especially since the plugin is registered once globally with the static SceneLoader.registerPlugin(). So my first attempt looked something like this:

SceneLoader.GetPluginForExtension('.gltf').loadAllMaterials = true;

However that did not work, any future load call would still have loadAllMaterials === false. I later figured out that loader plugins are recreated here (when they have a createPlugin method) for every load call. So the solution seems to be to add a OnPluginActivatedObservable observer, as suggested here.

However that seems quite counterintuitive to me, and I wonder what the reason for this is? It does create a bunch of single-use instances it seems, along with the required GC afterwards…

If I remember well it is because the plugins are not stateless. @bghgary could confirm ?

Yes.

Yes, this is how we do it typically. I want to spend some time to figure out a better way to pass in options, but I haven’t found the time yet.

2 Likes