[SOLVED] Array is undefined, issue with forEach

I try to communicate from ui to showroom


initialize() {
    this.cars = this.entity.findByTag('car');


    this.cars.forEach(car => car.enabled = false);



ok I communicate with showroom hideAll is called but the array cars is undefined why?

Hi @grzesiekmq,

The only way that can happen, since findByTag will always return an array, even empty, is if hideAll() is being called before the showroom.js script initializes.

I’d say check your loading order, if the showroom.js initialize() method indeed runs before hideAll().

1 Like

I changed the loading order so first is showroom second is ui
but the same

If you are able, try providing a simple project that reproduces the issue to take a look, it’s a bit difficult to debug this from the code shown.

ok I just changed in editor just swapped the scripts not in settings,
swapped in script component
works :slight_smile:

It sounds like this.entity.script.showroom.hideAll(); was being called in initialize?