let’s say you instantiate a bunch of objects in a scene (2d mostly), how would you go about removing a single object from them without deleting the whole lot?
been thinking about it for a few days and i can’t really see an answer for it anywhere on the internet. please let me know if anyone has an answer! thank you
Iterate through get_children(), check if the current element has the name of the node I want to delete, then queue_free that node? The answer depends greatly on your specific situation.
There are several ways to do it. I tend to favor having my objects determine when they are no longer needed, and having them queue_free() themselves. That’s not always practicable, but it’s very useful when it can be done.
i was using queue_free(), but it was sort of removing everything instantiated which i didn’t want. the mechanic is basically picking up water droplets to grow something, and i don’t all the objects disappearing at once lol
Presumably, you catch the droplet with something? Like a bucket or something? In that case, if the droplet has a collider, iterate through get_overlapping_bodies and maybe use a deferred queue_free?
i used this tutorial if that helps
what i just added from my end was a function to instantiate water droplets with a timer and the player picks and drops by pressing a button
In IMO that is not a good tutorial - to instantiate then remove and instantiate an instance for the purpose of moving/hiding/showing it, makes no sense at all.
You can instantiate and handle the position property of that instance to move it on the screen. Also, if you want to show or hide a Sprite2D or any other node that inherits from CanvasItem you can toggle the visibility property, like so:
Were you able to make it work ? … Don’t hesitate on making farther questions. I would suggest on going small and build upon that.
What I mean is: you could first try to create a drop item without worrying about any other thing. No character or other objects. Try changing its position, try showing it and hiding it. Get to understand HOW to do those things. Once you understand that part, you can jump into adding a bit more complexity by creating a character on the screen that interacts with this object. Go step by step, even more experienced developers do it exactly like that. If it takes long, that is fine. To build - even simple things, takes time
ill be giving it a shot this week! recovering from some medical stuff but i thought id try to atleast figure out what i would need look into the documentation or where to begin when i start to try it atleast!
and thank you for your advice! im sure ill get there soon