[SOLVED] Find the script in the scene

Hi! This should be simple thing, coming from unity this is common.

I have in a scene entity called “Pool” with script on it poolManager ( it has create method on it)
from some script i want to get this script
so i write

var Tests = pc.createScript('tests');

// initialize code called once per entity
Tests.prototype.initialize = function () {

    let pool = this.app.root.findByName("Pool");
    pool.script.poolManager.create();

};

// update code called every frame
Tests.prototype.update = function (dt) {

};

i get this error
Uncaught TypeError: Cannot read properties of undefined (reading ‘poolManager’)

so i guess it finds Pool entity but i can’t get to poolManager? Can somebody tell me what is going on. I can create add property that can hold reference to pool entity but i was wondering how to get it this way?

also i can get it from console like this:
pc.app.root.findByName(“Pool”)
so it can find it, but how to access script?
in console object doesn’t have any script property

That should work, can you post the example project to look at please?

Link was sent via PM

PoolManager script is empty/not been saved hence the object at runtime would be null

hmm strange, script is there (also if i put it as a reference then it works, drag in slot)

can you verify?

Probably because of the issue I reported.

maybe it was a combination of bugs
the point was that there was another entity with the same name in the scene :slight_smile:

The findByName will return the first entity it finds that matches the name. You may prefer findByTag for this reason or have a direct reference via script attributes