How to make instanced scenes unique?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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.

:bust_in_silhouette: Reply From: Zylann

To make an instance unique, it basically means you have to not use instancing, by removing the link B instances have with the B scene.

To do this, right-click on the instance in the scene tree, and choose “Make local”.

:bust_in_silhouette: Reply From: jarek

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)

isaelsky21 | 2022-10-29 19:12