#How to detect ONLY a Node being freed in the editor?

30 messages · Page 1 of 1 (latest)

cursive void
#

I need to detect a node being freed from a scene without using exited_tree() or child_exited_tree(), because I'm doing some automation in a tool script, and want to be able to have some of that automation happen when a node is deleted. The problem with using exited_tree() is this goes off when I switch scenes in the editor. This removes data when I don't want it removed from a resource that is tracking it. I can't seem to think of a good solution. Yes, I could create a way of deleting the node that specifically emits another signal then deletes the node, but what if I forget to use it? Then I'll be left with bad data from my automation. I need to figure out a way to detect a node being freed at edit time.

Things I've tried:

  1. I tried using notifications, but I must not understand how they work. This could still be the solution I'm looking for, but I'm just doing it wrong. This is what I'll be focusing my next googling session on, though.
  2. I tried overriding _notification(what) and doing if is_queued_for_deletion() which is a method in Object, but this did not work at all.
  3. I'm looking into doing something with scene_tree, but I don't know what yet. Still trying to figure out which thing would be relevant here from that.
  4. I investigated the possibility of finding/overriding some editor function like with a plugin, but I don't want to have to mess with plugin for that. I will if I need to, though.

I'll update if I figure this out, but I'd be super grateful for any insights.

frigid urchin
#

Instead of trying to detect when a node gets freed, why not control exactly when a node is freed. This way you know exactly when it happens and you then run whatever you want as a result of that clean up?

#

Not sure how you would do this. Just thought that attacking it from a different angle might help

cursive void
#

Well, because I'm trying to provide automation to a workflow that already exists. I don't want to add steps to the workflow for certain kinds of changes, because it adds places where mistakes can be made.

frigid urchin
#

Is there no way to rework the workflow maybe?

#

Trying to think outside the box here

cursive void
#

So, when I say workflow, in this case I'm talking about the standard workflow of "I don't need this node anymore, so I delete it from the scene tree". If I add a new way of "deleting" it, I'm adding overhead I have to remember to do every time I delete that specific type of node. I don't need this automation (and don't want it) for every node, just specific ones.

#

I'm being picky so future me doesn't screw things up, basically.

frigid urchin
#

Well, IMO it's going to be tough to do what you want without controlling the Nodes deletion yourself because Godot's editor itself is a "Game". As such, it's going to be treated as one. Godot will decide for you what is considered freed or not, leaving you no way to tell it otherwise.

cursive void
#

Well, like I said in what I was working on, I investigated various ways of detecting it. I don't mind that it "deletes" the node when I change scenes, I mind that when I detect it deleting the node, I want to detect only deletions called from a specific source. That source should be accessible.

frigid urchin
#

Maybe what you can do is create your own node that had the cleanup code you want and have other nodes inherit from that node

cursive void
#

Well, the other thing I thought of doing was just always having the automation only happen on _ready(), so that it would not have to care if something had been deleted or added. It would just build the data anew from whatever it finds each time. That is basically what I am going with now, btw. It would still just be nice to learn how to do more with the engine, though.

frigid urchin
cursive void
#

Another way to go about things would be to peel apart the PackedScene state and just grab the data from there. I've done it before, it's just a headache to get right sometimes.

frigid urchin
#

Something else you could look into is maybe creating a plugin or GD-Extension. You might have more luck with control over things at that level

cursive void
#

And it feels like doing brain surgery.

frigid urchin
#

What EXACTLY are you trying to do

cursive void
#

I have considered that. I've made attempts before, but that was back in Godot 3, so I haven't touched those in quite a while.

cursive void
# frigid urchin What EXACTLY are you trying to do

Well, I'm not even trying to do it anymore, but I have a game that would have a lot of entries and exits among different levels with different locations for each, and I wanted a way to automatically have the information scraped from the scene tree and put into a resource for easy wiring-up of the entries and exits.

#

Now I've realized it's not going to be much more work to just do it by hand, honestly.

#

I got all excited about automating it, because I always anticipate the learning exercise of doing stuff like that.

#

Would really be cool if I got that working, too.

#

What I had put together was working while I was still in that scene, but as soon as I moved to another scene, it deleted all the data, because I had made it so it would automaticall delete stuff I didn't need the moment I deleted it from the scene tree...Obviously, this backfired. lol

#

Deletion was not as discriminate as I had originally thought. At least, in terms of its detection. So...I DID learn something, after all. lol

#

I just had a thought that I could reverse the process and make it work in the opposite direction. I could populate the data, and automate that to add the nodes to the scene. lol I think that would work better. I'm still not doing it anymore, though. I might circle back and try something like that again.

frigid urchin
#

Ok so.... Do you really need help with this anymore or should we consider this solved?

#

Lol

cursive void
#

Well, it's not solved, AND I don't need help, anymore. Is that an acceptable answer? lol

frigid urchin
#

Lololol I guess it's as good as any

cursive void
#

Believe it or not, I thought of a few more things because of this conversation; if it makes any difference.