[SOLVED] How to hide and show with code

Hello, i need to be able to hide and show entities with code. I tried with no luck.

Hi @jus.co_ding_me_23,

To enable/disable entities you use the .enabled property. You can find an entity in the hierarchy using the find methods. For example to find an entity by its name and disable it:

var entity = this.app.root.findByName('Entity Name');
entity.enabled = false;

You can study the Entity class here:

thanks but i mean just hide it, not disable the entity entirely
but it still works, thanks

If your object is a model you can do the same on the model component. If it’s an element, on the element component:

var entity = this.app.root.findByName('Entity Name');
// if it's a model
entity.model.enabled = false;
// or if it's an element
entity.element.enabled = false;

The model component has show/hide functions:

2 Likes

i tried

if(this.app.keyboard.isPressed(pc.KEY_E){
    this.entity.model.hide();
}

it worked for the rocket but i did not work for the particle system, is there a way i can do the same thing with a particle system?

is a particle system an element?

The particle system has a different API:

If you need it disappear completely, you may have to disable the component or entity.

1 Like

ok

so i am gonna need @Leonidas 's advice for disabling and enabling

thanks you guys!!!