-
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hot reloaded nodes with "tool" enabled lose state and don't run initialization functions #908
Comments
On hot reload, the engine does:
|
@TitanNano what's the takeaway? You don't mention |
@Bromeon looking at the implementation, @Soremwar is currently not defining his Godot class in a way that can be hot reloaded the way he expects. Data that should be persisted between reloads has to be exposed to the engine. But from user's perspective, I get that this is not obvious. Maybe that is just a documentation deficiency? Tool classes are the only ones affected by this, as runtime classes do not have instances which need reloading. Hot reloading is also only supported in the editor, as far as I'm aware. |
@TitanNano So in this example exposing my variables with |
@Soremwar I just checked again, and you have to add |
If I'm reading the docs right, this would modify the scene file wouldn't it? |
@Soremwar yes I think so too. It feels like a bug in the engine. It is unclear to me why this was chosen, but properties must have the storage usage flag so they get backed-up before hot reloading. |
TBH it makes complete sense for a regular use case, since no Node would be expected to change their initial state after they have been instantiated. This is only true for I'm thinking of a hook (similar to I'm up to implement this if you guys think it's a good idea |
IMO this kind of hook that doesn't provide some kind of automatic re-evaulation of initial/onready values (a bit similar to init) would be pointless, since it already exists – Godot sends ObjectNotification::EXTENSION_RELOADED after reload which can be easily accessed on the user side. Albeit providing some kind of "on_recreate" function that behaves similar to "init" (read - automagically recreates all the values) could be very cool |
Given the class
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 reloadx
will be reset to1
as ifready
was never run.This might not seem like a big deal, until you test this with something like
This also applies for properties initialized with
OnReady
, so hot reload + tool is pretty much a no goThe text was updated successfully, but these errors were encountered: