Godot Version
4.4.stable
Question
Hi all. Could you please help me finding my mistake here?
I have two scenes.
Scene B contains a SubViewport with a mesh, a camera and a light. The scene has a script with a method to change the color of this box. Box and Material both have “Local To Scene” enabled.
extends Node2D
@onready var box: MeshInstance3D = $SubViewportContainer/SubViewport/MeshInstance3D;
func change_box_color(color: Color) -> void:
self.box.get_active_material(0).albedo_color = color;
Scene A now instanciates two instances of scene B and calls the change_box_color method of the scenes to change the box colors.
extends Node2D
@onready var scene_b: PackedScene = load("res://B.tscn");
func _ready() -> void:
var a = self.scene_b.instantiate();
self.add_child(a);
a.change_box_color(Color(1,0,0));
await get_tree().create_timer(1).timeout;
var b = self.scene_b.instantiate();
self.add_child(b);
b.position.x += 400;
b.change_box_color(Color(0,1,0));
This reveals that both visible viewports show the same content of the last instantiated scene instead of two individual ones. The red box disapears when the second instance is created.
Demo Project can be downloaded as zip: Download GodotTest.zip | LimeWire