I'm trying to make a tool-type scene that I can use in the Editor for designing levels. This scene has an exported variable that I can change in the editor and that is, when changed, meant to send signals to other nearby scenes (in the same sub-node as this scene). Think a switch with an "edible" boolean (so like true = "good" and false = "rotten") that transforms all the food in the scene from "poisonous" to "edible" and the other way around when switched.

As part of making this tool, I started by adding a setter to the variable, like this:

@export var pressed : bool :
	set(new):
		pressed = new
		if new == true:
			get_tree().call_group("food", "edible") # "food" is the Group that has a function "edible" that switches it from rotten to edible and the other way around

So this crashes in the last line with a Cannot call method "call_group" on a null value. Calling the same group using the same line elsewhere in the same script works perfectly. Does this mean I can't call a group from a setter? What am I doing wrong?

get_tree() returns null. That means you are calling the setter before the node is _ready.

How can I make sure the node is ready before calling it in this particular setup?

After a bit of saving an reloading, now it works despite printing lots of errors in the console for every switch and food items that are present in the level. So, when I launch the game, it goes through. It's probably just a coincidence that it even launches and maybe it wouldn't work if I changed some details, but anyway… now that it works I bumped into an even bigger problem.

And that is… all the food (that is now also turned into tool) reacts to emitted settings from the switch properly while in the editor, but once I launch the game everything in the whole level is in its default state. So I guess I was on the wrong track the whole time.