A scene instantiated twice do the same when only one is affected

Godot Version

Question

I have a “manekin” scene that you can punch and shoot and when damaged turns slightly red using a shader.
I instantiate the scene twice in a “testroom” and i notice that when i damage one manekin, the other one is also affected and i don’t know what to do.

this is the code of the manekin:

extends CharacterBody2D

@export var atravesable: bool = false;

func _ready():
	var rng = RandomNumberGenerator.new()
	var ran: int = rng.randf_range(0, 3.0)
	$spr.frame = ran;
	var rng2 = RandomNumberGenerator.new()
	var ran2: float = rng.randf_range(0, 3.0)
	$spr.flip_h = true if ran2 < 1.5 else false;
	$col.disabled = atravesable;

func _on_hitbox_area_entered(area):
	if area.is_in_group("damage"):
		Global.damage_animation(self.get_child(0));

the global function is this:

	node.material.set_shader_parameter("flashState", 0.35);
	var timer := Timer.new()
	timer.wait_time = 0.1;
	add_child(timer)
	timer.start();
	await timer.timeout;
	node.material.set_shader_parameter("flashState", 0);

this is the shader code:

shader_type canvas_item;

uniform vec4 color: source_color;
uniform float flashState: hint_range(0, 1) = 0.0;

void fragment() {
	vec4 PixelColor = texture(TEXTURE, UV);
	COLOR = mix(PixelColor, color, flashState);
	COLOR.a *= PixelColor.a;
}

i tried making it local in the scene editor of the testroom and it worked, but i don’t know what else to do to stop this

My assumption is that because you have two instances of the same scene, they will share the same material shader instance. I think there should be a function and/or editor option to make a copy of the shader material local to the scene. I can’t think of it off the top of my head

1 Like

this should work, there’s local to scene in material/shadermaterial inspector

1 Like