Skip to content

Hot reloaded nodes with "tool" enabled lose state and don't run initialization functions #908

Open
@Soremwar

Description

@Soremwar

Given the class

#[derive(GodotClass)]
#[class(base=CharacterBody2D, init, tool)]
pub struct Player {
	base: Base<CharacterBody2D>,
	#[init(val = 1)]
	x: i8,
}
#[godot_api]
impl ICharacterBody2D for Player {
	// Or enter_tree, it don't make a different
	fn ready(&mut self) {
		self.x = 0;
	}

	fn process(&mut self, _: f64) {
		godot_print!("{}", self.x);
	}
}

One would expect the console to spit out 0 all the time right? Well that would only be true when the scene is first opened, because if any change triggers hot reload x will be reset to 1 as if ready was never run.

This might not seem like a big deal, until you test this with something like

#[derive(GodotClass)]
#[class(base=CharacterBody2D, init, tool)]
pub struct Player {
	base: Base<CharacterBody2D>,
	#[init(val = None)]
	camera: Option<Gd<Camera2D>>,
}

This also applies for properties initialized with OnReady, so hot reload + tool is pretty much a no go

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugc: registerRegister classes, functions and other symbols to GDScript

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions