Setting a variable of another scene throws an error in tool mode

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TobiLa

I don’t know if I have a false understanding of the tool mode, but I have a script which I try to execute in the editor. The script just loads another scene an tries to set a member variable. However, when that script get executed in the editor it throws an error:

Invalid set index ‘test’ (on base: ‘Node2D (AnotherScene.gd)’) with value of type ‘int’.

here is my script:

tool
extends Node2D


func _ready():
	var anotherScene = load("res://AnotherScene.tscn").instance()
	anotherScene.test = 3

AnotherScene.tscn contains just a node attached to this script:

extends Node2D

var test

Can anyone tell me why this is not working? Is this a bug or my misunderstaning?

:bust_in_silhouette: Reply From: TheFamousRat

I think you need to add a ‘tool’ at the beginning of AnotherScene.gd. Try reloading the project otherwise (or just the scene), Godot sometimes needs that to make tool scripts work.