Getting specific children
Asked Answered
M

4

0

Hi all! I made my world a specific way that worked well, but now I need to change up the system to allow it to be bigger and more dynamic. In my old system, to get references to nodes like minable rocks and choppable trees I did a simple "get_tree().get_nodes_in_group("Tree")" and just looped through everything. Got me all my tree nodes and worked just fine! But now I need to split up my world into chunks, and this isn't going to work.

I have all the different chunks of my world as their own scene. Now I am bringing all those chunk scenes together into a single world scene. and I need each chunk to get all the rocks, trees, etc nodes that are children. But I have no idea how to do that.

I imagine I need to start with a loop. Then loop through every child? And check if the child is in a specific group? Or is there a better way to do this? SHould I be searching by group or should I be searching for a specific script on the node? (All these nodes have the same script of OBJECT)

Mithgarthr answered 26/2 at 17:37 Comment(0)
T
0

Mithgarthr In each chunk, have a dummy container node for every object type. Add all of the objects of specific type as its children.

Alternatively you can use regular groups for each chunk but name a group using chunk's unique id or coordinates, e.g. "trees#542" or "trees_12_4".

The third approach would be to use find_children(). It takes a regex pattern argument that lets you specify any imaginable criteria for name searching.

Thrift answered 26/2 at 19:20 Comment(0)
H
0

Mithgarthr I usually do it like xyz wrote.

I have a chunk scene and each chunk has child nodes for different things. Trees, terrain, buildings, rocks, navmesh.
This is also helpful if you want to disable things on chunks that are far away and you want only, for example, the terrain to be visible.

Hoeve answered 26/2 at 20:22 Comment(0)
M
0

Thrift That first one is actually what I ended up doing just messing around with things haha. It seems to be ok for now, I reference the blank node and get the appropriate child from there. So I think in my case, this is the best way to go. Thanks for the suggestion!

Mithgarthr answered 26/2 at 20:39 Comment(0)
M
0

Hoeve I think I'll be using a system pretty exactly like that. Seems to be the best way to go. Thanks!

Mithgarthr answered 26/2 at 20:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.