Dynamic template instanciation issue

Hi,

I have a project where i instantiate templates of characters at runtime. (PlayCanvas 3D HTML5 Game Engine)

I have a default character when project starts. The template associated (preloaded) has internal entities, and one named “Armature” with two components associated : Anim and Script.

When the project starts, the entity “Armature” with these two components works fine.

If i switch to another character, and come back to the first one by creating a new instance at runtime, the “Armature” entity doesn’t have the normal two components associated.

This the code is use to create an instance at runtime :

const newSkaterTemplate = pcApp.assets.find(skaterName, 'template');

const addSkater = (resource) => {
    var instance = resource.instantiate();
    const root = pcApp.root.findByName('Root');
    if (root) {
        root.addChild(instance);
    }
};

pcApp.assets.once('load:' + newSkaterTemplate.id, (asset) => {
    addSkater(asset.resource);
});
if (!newSkaterTemplate.loaded) {
    pcApp.assets.load(newSkaterTemplate);
} else {
    addSkater(newSkaterTemplate.resource);
}

How do i find the issue ? With code of script attached to Armature. The first time i have that :

and with the second instance :

Would it be possible to recreate the issue in a new project? From what I can understand from your post, creating a new instance of a template at runtime does not give the expected result?

If so, would you be able to create the issue in a new project or scene so that it’s easier for people to debug please?