[SOLVED] Target path for dynamic text inside 2D Screen?

I have a function that when it fires I want the value of a text string to display in a Text Element.

This Text Element is under the 2D Screen and is tagged as sctn_Text.

What’s the target path to change it’s string to a new string? I’m trying code like this to no avail:

this.app.root. 2D Screen? .findByTag(“sctn_Text”).element.text = “NEW TEXT STRING”;

I even changed the name of the 2D Screen to Menu for a cleaner path, it still produces an error (Uncaught TypeError: Cannot read property ‘findByTag’ of undefined):

this.app.root.Menu.findByTag(“sctn_Text”).element.text = “NEW TEXT STRING”;

What am I doing wrong? Thanks!

Hi @Jeffery.Wright,

So, findByTag is a pc.Entity method, in this case you should use it directly on the app root entity. Also it returns an array, that is a list of all entities that match that tag. Try changing your code to:

this.app.root.findByTag(“sctn_Text”)[0].element.text = “NEW TEXT STRING”;
1 Like

That worked a treat, thank you!

1 Like