|
|
|
|
Reply From: |
Magso |
The easiest way to pass values is by variables
Object1
var value
func _ready():
object2.value = value
Object2
var value
func _ready():
yield(get_tree(),"idle_frame") #wait one frame
print(value)
Here’s by parameters
Object1
var value
func _ready():
object2.custom_function(value)
Object2
func custom_function(value_parameter):
print(value_parameter)
And by signals (signals shouldn’t be used like this)
Object1
var value
signal custom_signal(value_to_pass)
func _ready():
emit_signal("custom_signal", value)
Object2
func _ready():
object1.connect("custom_signal", self, "the_custom_signal", [value_to_pass])
func the_custom_signal(value_to_pass):
print(value_to_pass)
but, how to check if there is an instance of an object in the scene?
If you mean referencing the nodes you either use get_node("path/to/node")
, $path/to/node
which is the same thing, get_node_or_null("path/to/node")
doesn’t error if the node doesn’t exist and finally using groups get_tree().get_nodes_in_group("object group")[0]
No. I mean, there can be multiple instances of an object on the scene.
How to get a list, for example, of all instances of object “a” in the scene?
Add a group name to that scene in the node tab and in the scene where there are multiple instances check if get_tree().get_nodes_in_group("your group").size() > 0:
Ок. Но как это сделать? Что вообще такое “группа”?
A group is an efficient way to reference nodes in bulk, other game engines call it tagging so you can give objects a tag such as all enemies can be tagged/grouped “enemy”.
Ok, figured out,
Спасибо)
You can either use add_to_group in gdscript or add a group name to that scene/node in the node tab as I mentioned above.
Edit: didn’t see your edit