Loading and setting models for 'other' players

if (this.players[data.id].entity.children[1].name !== data.av && 'Stock') {
    avatarurl = this.players[data.id].entity.children[1].name = data.av;
    console.log('Naujas modelis detected');
    console.log(avatarurl);
    players = this.players[data.id];
  this.app.assets.loadFromUrlAndFilename(avatarurl, null, "container", function (err, asset) {
     avatarentity = new pc.Entity('avatarModel');
        // Add the loaded scene to the hierarchy
     avatarentity.addComponent('model', {
            asset: asset.resource.model
          
        });
             console.log('loaded');
             players.entity.children[0].model.asset = avatarentity.model.asset;
             console.log(players); //It logs all players with same player ID, why?
             
        if (asset.resource.animations.length > 0) {
            avatarentity.addComponent('animation', {
                assets: asset.resource.animations    
            });
        }
    });

console.log(players); //It logs all players with their IDS

}}

};

This script gets model url from server data, downloads and setts it for other player
The problem: I’m testing it using 3 game instances, 2 players have models loaded (non stock, we exclude stock modeled players and leave them as it is), when the 3rd instance joins, it only sets model for one player, not for both, until I change it again, should I loop or…?

each player hasdata:av it has url of model which is setted when player selects model/avatar, stock means player uses stock model

Update: I can confirm it sets both player models for one player only
Fiksavimas

It does detect new player model changes, but fails to detect existing player models and assing to each

Hi @Newbie_Coder,

Any chance you can share a sample project with some steps to reproduce the issue? It may be easier to debug it like that.

Hey, I just fixed it!
It tried to load all models at once and prob got mest up somewhere, so I added a var to check if model finished loading so we can load other models.

I do have a few questions regarding this.
Should I unload the old model? I did players.entity.children[0].removeComponent(“model”);
And if yes, how?

Does these models stay in cache? .Glb as it seems they load faster after first load, any way to check this?

Do you guys have any performance tips? Thanks

if (modelLoads == false) {
if (this.players[data.id].entity.children[1].name !== data.av && 'Stock') {
    avatarurl = this.players[data.id].entity.children[1].name = data.av;
   // console.log('Naujas modelis detected');
   // console.log(avatarurl);
    players = this.players[data.id];
    modelLoads = true;
    this.app.assets.loadFromUrlAndFilename(avatarurl, null, "container", function (err, asset) {
        players.entity.children[0].removeComponent("model");
    players.entity.children[0].addComponent('model', {
            asset: asset.resource.model
          
        });
             //console.log( players.entity.children[0].model.asset);
            //console.log( players);
              modelLoads = false;
    });
}}
}
};
Network.prototype.removePlayer = function (data) {
    if (this.players[data].entity) {
        this.players[data].entity.destroy ();
        this.players[data].deleted = true;
    }
};


Would it remove all player data from ram after exit? Models etc