[Unity->BJS] How get a reference to the .ts script sitting on another game object

Hi there,

How can I refer to B.ts from A.ts, if A and B are on different Unity gameObjects?

@MackeyK24 I am pinging you - this is somewhat basic I could not find info/playground on this anywhere. Thank you in advance!

GetComponent function call

From a Script Component

const myscript:PROJECT.MyScriptClass = this.getComponent("PROJECT.MyScriptClass");

1 Like

Thank you very much for the answer and great tool.

@MackeyK24 Little update here: it works if both scripts are on the same game object. If they are on different game objects, the project compiles, but I get this error at runtime:

Uncaught TypeError: myscript is null

I put the code you wrote in the start() void.

Maybe this has something to do with script compilation order? I have tried moving all Editor Script Components to the folder “Editor” (Unity practice), but this breaks the project.

And if I try to put that code in the constructor or ready() void, I get this:
[11:08:16]: Unable to load from scenes/Main.babylon: Error in onSuccess callback

If on a different script use the this.manager.findSceneComponent

Thank you, works like a charm!