Topic was automatically imported from the old Question2Answer platform.
Asked By
jarek
I have a scene where I need many progress bars of different colors.
I made a scene A consisting of a single progress bar and added it a script funciton to change color from a script. This works.
Then I made another scene B with three above bars A instanced and made fg/bg color styles for all of them unique. So far so good. I can change color of each of those and the colors change independently.
Now on the main scene level I instance several B scenes. The hierarchy looks like this:
Main
B
A
A
A
B
A
A
A
B...
Once I change the color of first bar in the scene B, all instances of B change the color of this bar. How do I make them unique?
I tried clicking in the editor ‘Make sub-resources unique’ on all scenes but it didn’t make any difference.
Zylann’s solution works, but I’ve also found another one based just on scripting, which is better for me as I don’t need to make multiple instances local (still may benefit from modifying the instanced scene later):
This is in B, which is just the progress bar:
func set_colors(fg_color):
# Set foreground color
var fg = get("custom_styles/fg").duplicate()
fg.set_bg_color(fg_color)
set("custom_styles/fg", fg)
I know this is old, but since this answer helped me out, I wanted to mention that I just had to make two changes to make it work. Basically, just add a reference to the progress bar before the get and set like so:
func set_colors(progress_bar, fg_color):
# Set foreground color
var fg = progress_bar.get("custom_styles/fg").duplicate()
fg.set_bg_color(fg_color)
progress_bar.set("custom_styles/fg", fg)