Browse Source

Fix shared material bug: duplicate material per webcam quad instance

Godot 4 shares sub_resource materials across scene instances by default,
so all 3 camera quads were showing the same (last updated) texture.
Duplicating the material in _ready() gives each instance its own texture.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
master
melancholytron 3 weeks ago
parent
commit
e1dc0e7345
  1. 7
      scripts/webcam_display.gd

7
scripts/webcam_display.gd

@ -18,9 +18,12 @@ var _has_received_frame: bool = false
func _ready() -> void: func _ready() -> void:
# Get or create the material
# Get or create the material — duplicate to ensure each instance has its own
_material = material_override as StandardMaterial3D _material = material_override as StandardMaterial3D
if _material == null:
if _material != null:
_material = _material.duplicate() as StandardMaterial3D
material_override = _material
else:
_material = StandardMaterial3D.new() _material = StandardMaterial3D.new()
material_override = _material material_override = _material

Loading…
Cancel
Save