I tried to find it through this.app.root.findbyname or tag but it is returning null. PS: the text element is child of another object.
you could use an attribute
how? Can you please elaborate some more.
okay I understood. Basically what I want to do is to change a text element from scriptI don’t want to add it as an attribute because then I have to add it as a reference in all objects which is time consuming
Hi @Geniteam,
Could you share an example why findByName or findByTag didn’t work for you?
Here is the syntax:
var entity = this.app.root.findbyName('MyTextElementName');
var entities = this.app.root.findbyTag('MyTextElements');
The 2nd method will return an array with all entities that have this tag assigned.
Since the text element is a child you have to search first the parent element
this.app.root.findByName(‘parent’).findByName(‘child’)
if it’s an attribute as a script
this.app.root.findByName(‘entity’).script.nameofScipt.yourtextvariable = newvalue;
@ayrin actually .findByName()
method also searches the children of the node. Since it is called on the root
, it will look for that name among all the entities in the scene tree. Looking for a parent first will simply narrow down the search, in case you have a conflicting name somewhere else in the tree and you want to exclude it from the search.
True, but it’s pretty common to have conflict with names. Usually if it’s a child of entity and the script is in the main entity i use this,entity.findByName() to search in the childs.