diff --git a/cocos/terrain/terrain.ts b/cocos/terrain/terrain.ts index 9d4018bab1..7e123d1bae 100644 --- a/cocos/terrain/terrain.ts +++ b/cocos/terrain/terrain.ts @@ -896,7 +896,7 @@ export class Terrain extends Component { public onRestore () { this.onDisable(); this.onLoad(); - this._buildImp(); + this._buildImp(true); } public update (dtime: number) { @@ -1255,12 +1255,12 @@ export class Terrain extends Component { } } - private _buildImp () { + private _buildImp (restore: boolean = false) { if (this.valid) { return true; } - if (this.__asset != null) { + if (!restore && this.__asset != null) { this._tileSize = this.__asset.tileSize; this._blockCount = this.__asset.blockCount; this._weightMapSize = this.__asset.weightMapSize; @@ -1295,7 +1295,7 @@ export class Terrain extends Component { // build heights & normals const vcount = this.vertexCount[0] * this.vertexCount[1]; - if (this._heights.length !== vcount) { + if (this._heights === null || this._heights.length !== vcount) { this._heights = new Uint16Array(vcount); this._normals = new Array(vcount * 3);