[SOLVED] findComponent is not working

Hi, I am trying to find the frst instance of a component in my scene. I know it exists because I created it in the editor and it is never destroyed but my code is returning null. The script is attached to my root node.
I tried:

this.my_script=this.app.root.findComponent("myScript");

    if(this.my_script==null)
    {
        console.error("myScript not found!!"); //this prints
    }

…and this…

this.my_script=this.app.root.getChildren()[0].findComponent("myScript");

Whats going on? Why cant it find the component?

Cheers

the component is ‘script’ I think.
‘myScript’ is just a script you attached to ‘script’ component, but it’s not a component.

1 Like

Yeah sorry. Too early on the morning. I sometimes get confused that a script is not a component.

To find a script in root I need to do:

this.my_script=this.app.root.getChildren()[0].script.my_script;

Cheers