We can set objects to belong to another hierarchy using set_parent. Why can’t we get the id of the parent object with a set_parent function?
You want to be keeping track of this information yourself as you generate objects.
That’s what I’m doing right now, but it feels somehow wrong to be storing so many parent ids as I construct the game logic to allow other objects to reference to them. And it feels too tedious to send the parent_id to each object on construction when there (in many cases) should only be one of them in the game hierarchy. I guess it’s fine this way, but I’m running into some issues now where something which should be constructed is for some reason nil and I’m wondering if it has something to do w/ the method of accessing a global id reference.
The problem is in cases like this allowing a feature that can be convenient is too easily enabling devs to do the convenient route and tank their game’s perf when just keeping track of parents manually is much faster.
Full debug inspection of the scene graph is the better feature to lobby for in your case.
Alright thanks, yeah that’s what I’m doing and I was using the performance benefits as an excuse to design it this way, so I’m glad to have some corroboration of my madness
What @pkeod said is correct and why we don’t encourage using scene graph traversal functions.
However, for consistency with gui.get_parent()
, we will add a go.get_parent()
relatively soon.
Wow, can’t wait!
I wasn’t able to find the old ticket where this was discussed so I created a new one: https://github.com/defold/defold/issues/5220