Hello once again, i have yet another incident i came across. Sometimes when nodes get added to the tree, instead of appearing with their usual names, some characters get added to it, along with some sort of ID, like instead of "Node01", it renames itself to "@Node01@129" or something like that. This can cause problems obviously while attempting to find nodes by name, which i kinda fixed by adding a process that checks if the node has that name or not and then renaming it if it doesn't, but that's just patching it superficially, my question is, why does it happen?, how can i prevent it other than with my previously-mentioned solution?
Nodes randomly renaming themselves with @ names
So basically it's just the engine + my code failing to delete the previous node before adding the other one and thus renaming the new one? huh
- Edited
@Xrayleader said: So basically it's just the engine + my code failing to delete the previous node before adding the other one and thus renaming the new one? huh
Yes, I would guess your issue is you not freeing the previous node before instancing a new one. I typically see this when instancing many of the same node into a scene, like bullets spawning from a gun. If you print out the name of each bullet as it spawns you would see each one increment as "@Bullet@12312", "@Bullet@12313" and so on. If you were to delete all bullets before spawning a new bullet and printed the name you would see "Bullet"
If there is only supposed to be one of that entity at a time then you can do a check first to free that node before spawning the new one.
if parent.has("my_node"):
parent.get_node("my_node").queue_free()
else:
#code that spawns your node
...
If you want there to be multiples of the same node then you would probably want to use the group system versus trying to find the node by name. That way instead of doing:
parent.get_node("my_node") #grabs one object
You can grab all of the objects in that group by checking the parent node:
#check for bullets in my scene
var children = parent.get_children() #comes back as an array if I remember right
for child in children:
if child.is_in_group("bullet"):
do_thing()
else:
print("not in bullet group")
Can't believe it didn't occur to me, i'll keep it in mind for future issues. I actually found a way around the issue, and it was to rename the node that's going to be deleted so the newer node does not get renamed, still a bit of a patchwork, but at least it doesn't have to constantly check if the node has a different name
Thank you all for reading and giving your input once again!