Using TOOLKIT SceneManager with an AssetContainer

Hello,

I recently came back to BabylonJS and wanted to try a CharacterController.
I found the great example from @MackeyK24 , which is awesome ! So I dig deeper in what the TOOLKIT namespace provides.

My problem is that I slighlty modified the example to use an assetContainer to load the Player.
And then, use the instantiateModelsToScene function to add this model into the Scene, as the doc says.

But doing this prevents the PROJECT.ThirdPersonCameraController to work correctly, event if the Scene Inspector says the two ways of doing produce the same TransformNode as a result.

You can try by yourself and see that the Character does not play animations, and only turn forward and back, not left or right : https://playground.babylonjs.com/index.html?BabylonToolkit#V9AUOR#2

I saw in a previous post from @labris (Performance Difference between Clone, Instance, and Containers - #2 by labris) that using the instantiateModelsToScene function is a good way to clone animations and skeletons, is there something I am missing ?

(this is the original playground example if you want to compare : Babylon.js Playground)

Thank you in advance !

YOU CAN NOT CREATE INSTANCES OF SKELETAL MESHES.

But you can instantiate prefabs as clones from an Asset Container:

// Instantiate the PREFAB as a CLONE directly from the container (Note: Parses PlayerArmature And All Its Scene Components)
// Like the TOOLKIT.CharacterController and the TOOLKIT.AnimationState component the the PROJECT.ThirdPersonPlayerController
// script uses to controller the movement and play the set the approiate animation state. Makes Clones.
const player = TOOLKIT.SceneManager.InstantiatePrefabFromContainer(this.assetsContainer, "PlayerArmature", "PlayerArmature");

Your Fixed Playground

1 Like

I know you can’t create instance but I thought the instantiateModelsToScene function check if it is possible for you and decide to make a clone instead.

Anyway, thank you very much, these TOOLKIT functions are very useful and I can continue to experiment :wink: