How to make something "Unique"

Godot Version

4.7.2 stable

Question

Hello, I am making it to where if a character touches an object it changes the color of that object. I have tow of these objects in the scene and when the character touches one of them it chages the color of both of them. Is there a way to make the objects “Unique”? (idk if that is the right term)

heres the tiny code i have rn that makes it workextends Area3D

extends Area3D

## Function to change the color of the flag based on the color of the character
func _on_body_entered(_body: Node3D) -> void:
	$Flag.mesh.material.albedo_color = Color(0,0,255)
	
	## adding +1 to the global flag count
	Global.flag_count = Global.flag_count + 1
	

In the editor, tick “Local to Scene” inside the material’s Resource section

If you want to do it in code, you could do something like this:

var _mat_dupe := false

...

func _on_body_entered(_body: Node3D) -> void:
	if not _mat_dupe:
		_mat_dupe = true
		$Flag.mesh.material = $Flag.mesh.material.duplicate()
	$Flag.mesh.material.albedo_color = Color(0,0,255)

This way it only creates a unique material when needed.

Ah, thank you this has worked!