How do you add unique instances of a shader to multiple nodes in a scene? Godot 4

I have multiple “interactable” objects in my game all extend the InteractableBody class that sets some stuff up so the player can interact with the object. I am trying to add an outline shader to the sprite so i can outline objects that are able to be interacted with. This is my code right now that does this however this currently just applies the outline to the first object with the shader, no matter what object. I had a previous version working where all objects had the outline and were all being changed when only one object was being updated.

This is my current code for applying the shader:

class_name InteractableBody
extends CharacterBody2D

@export var string_name : String
@export var icon : Texture2D
@export var interact_range : float
@export var interactable_sprite : Sprite2D
@export var outline_shader : Shader

var player_node : Player = null

func _ready():
    add_to_group("interactable")
    var material_instance = ShaderMaterial.new()
    var new_shader = outline_shader
    material_instance.shader = new_shader
    interactable_sprite.set_material(material_instance)
    hide_outline()

func setup_player(_player_node):
    if _player_node:
        player_node = _player_node

func _process(delta):
    if player_node:
        if player_node.global_position.distance_to(global_position) < interact_range:
            if player_node.interactable_objects.has(self) == false:
                show_outline()
                player_node.add_interactable(self)
        else:
            if player_node.interactable_objects.has(self) == true:
                hide_outline()
                player_node.remove_interactable(self)

func show_outline():
    var shader_mat : ShaderMaterial = interactable_sprite.material
    shader_mat.set_shader_parameter("color", Color(1.0, 1.0, 1.0, 1.0))

func hide_outline():
    var shader_mat : ShaderMaterial = interactable_sprite.material
    shader_mat.set_shader_parameter("color", Color(1.0, 1.0, 1.0, 0.0))

I tried to apply an outline shader to each object in a group and then be able to turn the shader on/off on each node one at a time. What actually is happening is only the first node with the shader has an outline and that outline is being updated no matter what node i am interacting with.

Here are some solutions, which may work depending on your specific setup:

  1. Instead of setting the shader material, create a uniform within the shader to set the outline’s color. Then you can change the shader’s uniform. This might be the solution you are looking for because you are trying to change the shader itself instead of the node you are applying it to.
  2. Create a second object whose only function is to hold the outline. Then, hide it or show it depending on your needs.
  3. If you insist on actually changing the shader, you can duplicate your shader in your ready function to make it unique. Then when you change it later this should not affect the other copies of the shader.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật