I have an entity (a button) with a child entity (some text) attached. I want to change the colour of the childs text from within the main entities script. I tried:
myButton.children[0].element.color = new pc.Color(0,0,0);//black
But I get the error: Cannot set property ‘color’ of undefined
Am I doing something obviously wrong here? Is this not how to access child elements?
Without seeing the project it’s hard to say. What do you get in the console when if you log myButton.children ? I’ve run into issues before where, for whatever reason, there are empty entries in the children array.
The children are there but I just noticed some very strange things going on in the graph. Whenever I switch scenes the root node is duplicated like so… Is that normal???
Maybe this has something to do with it?..along with other issues Im having. I never noticed this until now.
But I thought the new scene would be placed inside of the original root, not duplicated. Is there a way to transfer the new scene into the original root without creating a new root?
No, it is added to app.root. When loading a scene, you will always get the scene’s root entity added to it.
The easiest fix for your project (as you are loading multiple scenes in your project) is to change the name of the Root entity in the Init scene to something else.
Anywhere else you load a scene, instead of searching for ‘Scene’ as your old hierarchy, search for ‘Root’.