Script does not recognize sub elements

Yep, the code is correct.

Those names in the scene tree don’t really tell me what those entities are. I see the hierarchy however. Is “Beige” a button element, that has many other buttons as children? If yes, what is the idea behind this approach? This doesn’t sound right, as usually the children of a button are only cosmetics, like an image, or a text label. You generally don’t want to put any other active elements as children under the button. Its like the end of the branch of your scene hierarchy tree. Don’t grow another branch from a leaf.

So, what’s the idea here in your feature? Describe the user flow, so I can recommend a proper path.

Hi @LeXXik, this is exactly how you have interpreted it, Beige a button element that has many other buttons as children. It’s the best way I can imagine to solve a hierarchy problem, but it’s probably misfocused. I will try to explain a little how I want the button system and its hierarchy to work, I hope it is clear enough and you can understand it and give me your opinion:

The “TOP BASE A”, “TRIM STRIPE B”, “TRIM STIPE C” and “TRIM STRIPE D” buttons are main buttons that select a specific part of the plane in which we want to apply a certain range of color (beige, yellow, red, gray, purple, green and black), then what I have thought is that the beige, yellow, red, gray, purple, green and black buttons are secondary / children of each
button “TOP BASE A”, “TRIM STRIPE B”, “TRIM STIPE C” and “TRIM STRIPE D”. In turn, each button that defines a color range (beige,
yellow, red, gray, purple, green and black) when pressed, it must display a set of buttons with multiple colors that correspond to the chosen color range. In other words, if you press the “beige” button, a variety of beige tones are displayed that will only be applied to the part of the plane previously chosen with the “TOP BASE A”, “TRIM STRIPE B”, “TRIM STIPE C” and "TRIM buttons. STRIPE D ". Actually, the buttons that change the colors are those of the third level, that is, the ones that are displayed when you press the button corresponding to the color range you choose.
If you remember a post of mine from a few weeks ago, I told you that I wanted to write a script that could work with hierarchies.
Well it was just for this project.
I determined that it would be too complex and tedious to have all the buttons on the same level of the scene tree, if I do it from this
way I imagine dozens of scripts that control each one to a button. So I thought about putting the buttons together like a tree in the scene:
The buttons “TOP BASE A”, “TRIM STRIPE B”, “TRIM STIPE C” and “TRIM STRIPE D” would be the trunk of the tree, the buttons “beige”, “yellow”, “red”, “gray”, " violet “,” green “and” black "would be the branches, and the colored buttons for each range would be the leaves. By doing this
So I imagine a single script (or as few as possible) that can control each tree indicating parent / child functions as I am trying to achieve. I hope you have understood what I am trying to achieve.

The perfect script should say something like this:

First event / function:
When the “TOP BASE A” button is pressed, the “beige”, “yellow”, “red”, “gray”, “violet”, “green” and “black” buttons that correspond to the “TOP BASE A” button should be displayed and keep hidden the" beige “,” yellow “,” red “,” gray “,” purple “,” green “and” black “buttons corresponding to the” TRIM STRIPE B “,” TRIM STIPE C " and " TRIM STRIPE D " button.

Second event / function:
When the “Beige” button is pressed corresponding to of the “TOP BASE A” button that was pressed / selected in the first event / function, all the color buttons (Beige Color Range) corresponding to the “Beige” button must be shown and all the color range buttons corresponding to the buttons called “yellow”, “red”, “gray”, “purple”, “green” and “black” must be kept hidden

Third event / function:
When is press some color button in the beige range that was activated / displayed when the “beige” button was pressed in the second event / function, it are must put that color/material in the object to which to the refers the “TOP BASE A” button.

Captura03

Sounds like you can do this with two scripts.

One for each button that represents a part of the product that shows/hides the buttons for each colour possible.

And another one for each colour button that referenced the material and the colour to change it to.

Right, got you. Basically, as @yaustar said. So, there are 2 ways in doing this, and it simply depends on your app design:

  1. You have multiple base parts. Each base part has one or many shared or unique colors.
  2. You have multiple base parts. All base parts share the same set of color choices.

Option 1:
You can keep your current setup, and only adjust it so that the Buttons are not parents. For example:

Base A               // Entity
  |- Button A        // Button Element
  |- Colors          // Entity
  |    |- Color A    // Button Elements
  |    |- Color B
  |    |- Color C
Base B
Base C

Colors entity can be disabled at start. Since it is a parent, all its children will be disabled too. When ‘Button A’ is clicked, you can enable Colors entity, which would also enable all its children.
The trick here is to know, which Button was actually pressed, since all Base entities (A, B, C) has the same script attached. Was it Button A from Base A? Or Button B from Base B? The answer would allow you to know which Base colors to show and which base colors to hide.
One way to solve it is to hide absolutely all colors on a button click, and then show only the ones that are under the current parent of the Button that was clicked. There are different ways and perhaps you can find another option that works for you better. No right or wrong here.

Option 2:
If all color choices are same for all base parts, then you can simplify the setup:

Logic              // Entity
Bases              // Entity
  |- Base A        // Button Elements
  |- Base B
  |- Base C
Colors             // Entity
  |- Color A       // Button Elements
  |- Color B
  |- Color C

In this case, your Logic entity could have a script that would listen for button clicks. It would catch the base part button click and a color button click, save them in its properties (this.base, this.color). When color button is clicked, it would also change the mesh material based on the selections stored in those properties.

2 Likes

Hello friends, thank you very much for your help. @LeXXik I think option 1 is the closest to what we have at the moment, it also seems to me that the script created yesterday can be the base to start with, what do you think? Let’s get to work, I will be consulting you, I hope you can guide me in this challenge
A query, the Base A entity and the Colors entity should not be buttons, right?

Yes, that is correct. You can use the current script for the option 1.
And yes, Base A and Colors from my diagram should be plain empty entities, not button elements.

Now I understand my previous mistake, so I put it together now

Nope, EntityTopBaseABeige should be under EntityTopBaseA, not under button ButtonTopBaseA.

By the way, you can use spaces in your entity names, e.g. Top Base A is a good name and easier to read than EntityTopBaseA.

Hello @LeXXik, @yaustar I wanted to tell you that the UI system works perfectly, I am very grateful. They are very friendly, really supportive to share knowledge. Thank you gentlemen.

1 Like