Why export variable affect all scenes?

Godot Version

4.2

Question

Hi,
I’m curently making my first project (3D) with Godot 4.2. I use GDscript.

I have created a scene whitch is a light bulb. It has a @export variable to enable/disable the lamp from the editor.

When i put this scene in the main scene it work fine, but when i add more of it, editing one lamp affect all of them! Why ?

Here is my code:

extends Node3D
@export var is_enabled = true

func _process(delta):
	$Spotlight.visible = is_enabled
	$LightBulb.material_override.emission_enabled = is_enabled

Is this a code related problem or my conception of how scenes works is wrong (i was thinking every copy of a scene where individual)

Thank you.

editing one lamp affect all of them

How are you editing the lamp? If you’re using the checkbox in the Inspector, it should only apply to that specific node. However, if you’re changing the value in the script itself, it will apply to all instances of the scene.

Ah, I see you’re using a material. I believe the material resource is shared among all instances of the node. If you expand the material and choose “Local to Scene” it should start applying to that scene/node only.

See Resource.resource_local_to_scene for more.

Capture

I use the checkbox of the @export variable “is_enabled”.

It’s confusing. The variable is in the inspector and is created from the script.

If you do it inside the scene/node itself, it will override all of the copies.

You have to create new copies of the scene/node and then check the box ‘is_enabled’ from OUTSIDE on each copy.

I’ve finally found.

So first in the main level scene where i put all my lamps i must select them and, in the inspector, select “Make Sub-Ressources Unique”.
Solution

Then, like GBWD said, in the scene of the lamp, go to “Resource” and ckeck “Local to scene” property of everything that need to be individual (meshs, materials, etc.)

I find the process pretty tedious (here it’s only 2 lamps but i will get tens of them per level so…)

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