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
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