TypeError: this.app.root.findByName(...).script.game is undefined

I am trying to toggle on ‘2D screen’ component in my project. But when i try to access it in contact script i get this error: “TypeError: this.app.root.findByName(…).script.game is undefined”
https://playcanvas.com/editor/scene/1072109

Hi @mortal_phoenix ,

Both of your 2D screen elements do not have the game script attached to them, and that is why it is complaining that it cannot access the game script, you need to attach the game script to the 2D screen element:

1 Like

I have attached the script to root. Please enlighten me on how can i access this script in control.js

@mortal_phoenix by doing this:

this.app.root.findByName("Root").script.game

2 Likes

Thanks for the help