How to make resource unique from script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By damncoder

For now i know how to make resource unique ftom editor:
press on resource > drop down menu > make unique.

Any ideas how to make it from script?

Thanks in advance.

1 Like
:bust_in_silhouette: Reply From: Zylann

You can make a resource unique from script by creating a new instance of it with duplicate() and setting it up in place of the original.
Example with a material on a sprite:

sprite.material = sprite.material.duplicate()

It works! Thank you.

damncoder | 2018-10-31 07:31

You could also set property of the resource: resource_local_to_scene.
Godot Q&A explanation
Godot documentation on Resource

Roman Koziolek | 2020-06-10 01:50

I believe this only works when set in editor and then instanced.

Zylann | 2020-06-10 12:31


Wow! Thanks for this thread from many years ago!

I had a similar problem but with cloning/duplicating Area2Ds but the CollisionShape2D’s actual shape (RectangleShape2D) was still shared even after duplicating. node.duplicate(true) also didn’t change this.

The following now worked:
(Maybe it helps somebody else too)

var new_area_2d := $TemplateArea2D.duplicate()
new_area_2d.get_children()[0].shape = new_area_2d.get_children()[0].shape.duplicate()

try this:

var a = b.duplicate(true)