How Do I Find and Access a Text Element of an Entity?

I want my script to find some entity, find its text element and modify the text. As a wild guess I thought it might be something like the following but its not :):"Text_Mattress_Name").element.text;

this.modelNameText= "Hello";

You got it right, though you can’t reference a string value in another property. Text, number and boolean values are always passed by value not by reference in Javascript (unlike objects).

Try doing it like this:

this.modelNameElement ="Text_Mattress_Name").element;
this.modelNameElement.text = "Hello";

Great. Thank you!

1 Like

I tried to do the same for accessing the textures of an image element but get the error:

Cannot create property ‘_glTexture’ on string ‘P’

My code:"Mattress_Main_Image").element;

…where my JSON image[0] is “someMattress.png”

Maybe image elements are handled differently or do I need to define the full project path to the texture in my JSON?

element.texture is expecting a pc.Texture object, not a string

1 Like

If that is the name of your image asset you need to grab it from the assets registry first and then use its texture resource:

var imageName = this.appManagerScript.mattressData.brands[this.appManagerScript.currentBrand].products[this.appManagerScript.currentMattress].images[0];

var imageAsset =;

if( imageAsset && imageAsset.loaded){
   this.mattressImage01.texture= imageAsset.resource;