Skip to content

Commit

Permalink
Grid render component fix (#7384)
Browse files Browse the repository at this point in the history
* Grid force creation of render component

* Removed addRender call and error if script already has render component

* Replaced throw with console error

* Added return back
  • Loading branch information
kpal81xd authored Feb 26, 2025
1 parent 469e821 commit dd63772
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions scripts/esm/grid.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ class Grid extends Script {
*/
static RESOLUTION_HIGH = 2;

/**
* @type {boolean}
* @private
*/
_addedRender = false;

/**
* @type {ShaderMaterial}
* @private
Expand Down Expand Up @@ -180,15 +174,17 @@ class Grid extends Script {
_resolution = Grid.RESOLUTION_HIGH;

initialize() {

// ensure the entity has a render component
if (!this.entity.render) {
this.entity.addComponent('render', {
castShadows: false
});
this._addedRender = true;
// check if the entity already has a render component
if (this.entity.render) {
console.error('The entity already has a render component.');
return;
}

// create render component
this.entity.addComponent('render', {
castShadows: false
});

// create shader material
this._material = new ShaderMaterial({
uniqueName: 'grid-shader',
Expand Down Expand Up @@ -254,7 +250,6 @@ class Grid extends Script {
* @private
*/
_set(name, value) {

if (!this._material) {
return;
}
Expand Down Expand Up @@ -331,11 +326,7 @@ class Grid extends Script {
}

destroy() {
this.entity.render.meshInstances = [];

if (this._addedRender) {
this.entity.removeComponent('render');
}
this.entity.removeComponent('render');
}
}

Expand Down

0 comments on commit dd63772

Please sign in to comment.