Skip to content
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

Saving a scene containing a tool node will call PREDELETE notification, while not being deleted #17681

Closed
Zylann opened this issue Mar 21, 2018 · 4 comments · Fixed by #49741
Closed

Comments

@Zylann
Copy link
Contributor

Zylann commented Mar 21, 2018

Godot 3.0.2

Is this behavior intented? I thought NOTIFICATION_PREDELETE would be sent only before the node to be deleted, but it happens anyways when I save the scene, while no node gets deleted (at least I see no reason for this to happen in this situation).

Not only it calls PREDELETE, but also _init() gets called too, BEFORE the predelete... why is all this even done?
I'm saving a scene containing a terrain, which is quite heavy. These steps seem to be unnecessary.

Test project:
PluginPredeleteCalledOnSave.zip

  1. Open the main scene, notice the log prints:
Init
Enter world
Enter tree
Ready
  1. Save the scene right away, notice this gets printed:
Init
Predelete
@santouits
Copy link
Contributor

santouits commented Apr 22, 2019

This seems to be the reason for the notifications.

godot/editor/editor_node.cpp

Lines 1165 to 1172 in 1bbe95b

// force creation of node path cache
// (hacky but needed for the tree to update properly)
Node *dummy_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE);
if (!dummy_scene) {
show_accept(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."), TTR("OK"));
return;
}
memdelete(dummy_scene);

@KoBeWi
Copy link
Member

KoBeWi commented Jul 10, 2020

Still valid in aeccd1e

@KoBeWi
Copy link
Member

KoBeWi commented Nov 17, 2020

Ok so I encountered a similar issue, caused probably by the same thing:

tool
extends Node2D

export var test: int setget setest

func setest(t):
	test = t
	prints("test", get_instance_id())

Change test to 1 in the inspector and save the scene. With each save, the script will print with different ID each time.

@KoBeWi
Copy link
Member

KoBeWi commented Jun 17, 2021

This is caused by the dummy node created when saving scene (this is the one that calls the method). See #47828

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants