0 votes

I want to pass a value from one object to the next. The problem is that it looks like there is no way to do this cleanly. This is what I have deduced after reading the manual on finding nodes:
enter image description here
Green shows what I want. I will first need to ask the parent for a list of children, then tell it to change the value in the child.

I can't use the hard code path system Godot wants me to, the whole getNode("Path\Path") thing, because my game will have objects spawning dynamical.
Searching every object in the scene to find one would be slow.

This image shows my setup for now, but it won't stay this simple.

enter image description here
Also looks like Godot has no way of selecting object at run-time? Feels like I am missing something big here.

in Engine by (1,482 points)
edited by

1 Answer

+1 vote

I had something like this a while ago, but it involved collision, so it was not that problematic. If You have a collision there, then You easily get the node that collided and can immediately connect+emit a signal to it or just call it's method directly.

For a totally abstract setup I'd probably keep a list of As and Bs in Level node for fast access and I would probably keep a reference to Level node in every other node also for fast bug-free access.

It is hard to say on which particular condition You do select A2 for B2, but maybe they are related in some way - like collision, ray cast, adjacency - which could help get the reference instantly.

My answer is based on two weeks of experience in GODOT, so maybe there would be someone smarter to help :).

by (241 points)

Thanks to you , I managed to solve it. As you say I use collisions, for this to work the script must be attached the the parent node, because it is the only node that knows where the children are.

In other words, it works in reverse from what I was attempting.

Looking at how buttons work and how Godot checks every item one by one for input, it is safe to say that this is intended. So I assume it has a octree or something.

Thanks for pointing me in the right direction.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.