[SOLVED] Change terrain troubles

Hello, from a certain version of the engine this script doesn’t work as it was doing previously, someone has some clue? It should delete the previous terrain created by heightmap and replace it with a new one (useful to change location in game)

changeTerrain: function() {
            // disable all the houses
            var house=app.root.findByTag('house1');
            for(var x=0;x<house.length;x++) {
                house[x].enabled=false;
            }
            house=app.root.findByTag('house2');
            for(var x=0;x<house.length;x++) {
                house[x].enabled=false;
            }
            house=app.root.findByTag('house3');
            for(var x=0;x<house.length;x++) {
                house[x].enabled=false;
            }
            // get the localMap value
            this.lM=app.root.findByName('Player').script.player.localMap;
            var img = app.assets.get(this.heightMap[this.lM]).resource.getSource();
            var model = this.createTerrainFromHeightMap(img, this.subdivisions);
            var collisionModel = this.createTerrainFromHeightMap(img, this.subdivisions / 2);
            //var buildings = app.assets.get(this.dbTowns).resource;
            
            //var oggdata = this.parseTownData(buildings);
            this.entity.removeComponent('model');
            this.entity.model=null;
            this.entity.addComponent('model', {
                type: 'asset'
            });
            //this.entity.model.castShadows=true;
            this.entity.removeComponent('rigidbody');
            this.entity.rigidbody=null;
            this.entity.addComponent('rigidbody', {
                type: 'static'
            });
            this.entity.rigidbody.friction=1;

            this.entity.removeComponent('collision');
            this.entity.collision=null;
            this.entity.model.model = model;
            this.entity.addComponent('collision', {
                type: 'mesh'
            });
            this.entity.collision.model = collisionModel;
            
            this.placeBuildings();
        },

What does it do instead?

oh right :stuck_out_tongue: if overlaps the terrains

Actually looks like a bug looking at the engine. The logic path for removing the component doesn’t seem to remove the model from the layer which may be why it’s still rendering.

I would disable the entity before removing the components.

Thanks @yaustar if i disable the entity, remove the components, and enable it again the old terrain disappear. Now i have to check why the trees floating lol