Run copies of scenes scripts independantly

Godot Version

4.2.2

Question

I have an issue where I want to have 2 copies of the same enemy scene but I want the scripts for each to run independantly of each other.

I have 2 test enemies that I have written some very basic code for to test this. The issue I am getting is if I colide with the raycast of 1 enemy, the animation plays on both at the same time. I’m very confused because the health variable does act independently? Please can someone tell me in what way I am being dumb here!

extends CharacterBody3D

var health = 500
@onready var aim_cast = $EnemyAimCast
@onready var animation_player = $AnimationPlayer

func _process(delta):
if health <= 0:
queue_free()

if aim_cast.is_colliding():
	animation_player.play("2_alert")
else:
	animation_player.play("1_idle")

Off the cuff, I’d say you need to “make local to scene” or “make unique” the animation or associated resource. Not on my computer or I’d give you a better answer.

Edit: generally when one change is affecting many things, it is because Godot is using only one copy of that resource to be efficient. And the fix is usually something like what I said above.

2 Likes

Bang on thank you very much.

incase anyone else would find this usefull.

The animation was basically changing the mesh colour of the eyes to red or white depending on if there was a colision on the raycast.

I right clicked the mesh → sub recources → surface material overide then under resource in the inspector clicked on Local to Scene.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.