Adding @julien-moreau
Hi @theflyhawk !
I can see you have attached the script to a mesh. That means your script should extend the “Mesh” class from “@babylonjs/core”. You can find more informations about that on this documentation: Editor/attaching-scripts.md at release/4.0.0 · BabylonJS/Editor · GitHub
Also, if you want to get references from other components in your script, you can read this issue: How to get script from another mesh? · Issue #261 · BabylonJS/Editor · GitHub where documentation will be updated to integrate that example.
In other words, in your script that extends “Mesh” you can access “this.material”, “this.isPickable”, etc. like:
import { Mesh } from "@babylonjs/core";
export default class MyScriptIHaveRenamed extends Mesh {
/**
* Override constructor.
* @warn do not fill.
*/
// @ts-ignore ignoring the super call as we don't want to re-init
protected constructor() { }
/**
* Called on the node is being initialized.
* This function is called immediatly after the constructor has been called.
*/
public onInitialize(): void {
console.log(this.material);
console.log(this.isPickable);
// etc.
}
/**
* Called on the scene starts.
*/
public onStart(): void {
// ...
}
/**
* Called each frame.
*/
public onUpdate(): void {
// ...
}
}
2 Likes