Hi, @julien-moreau
As you know, I try the new wonderful editor and have a question. Is it possible for .ts files to get objects
generated by scripts?
For example, “ground” in the picture is located preview and graph window.
I can get the objects by the following script.
import { Mesh, FreeCamera,Scene } from "@babylonjs/core";
import { fromScene} from "../tools";
export default class example extends Mesh{
@fromScene("ground")
private _ground :Mesh;
public onStart(): void {
console.log(this._ground.name);
}
}
Then, console shows “ground”.
On the other hands, I can not get the object “ball” generated by class example1.
import { Mesh, FreeCamera,Scene } from "@babylonjs/core";
export default class example1 extends Mesh{
public onStart(): void {
const ball = Mesh.CreateSphere("ball", 10, 1);
}
}
import { Mesh, FreeCamera,Scene } from "@babylonjs/core";
import { fromScene} from "../tools";
export default class example2 extends Mesh{
@fromScene("ball")
private _ball : Mesh;
public onStart(): void {
console.log(this._ball.name);
}
}
Then, the error below shows in browser.
ball.ts:57 Uncaught TypeError: Cannot read property 'name' of null
at Mesh../src/scenes/scene/ball.ts.ball.onStart (ball.ts:57)
at Observer.callback (tools.ts:33)
at Observable../node_modules/@babylonjs/core/Misc/observable.js.Observable.notifyObservers (observable.js:286)
at Scene../node_modules/@babylonjs/core/scene.js.Scene.render (scene.js:3366)
at index.ts:32
at Engine../node_modules/@babylonjs/core/Engines/engine.js.Engine._renderFrame (engine.js:830)
at Engine../node_modules/@babylonjs/core/Engines/engine.js.Engine._renderLoop (engine.js:845)
Is it a way to get such objects in scripts?
Thanks in advance