How to pass arguemnt to method in call_group()

Godot Version

v3.6.2.stable.official [3cd3caab6]

Question

i want to pass player.position to enemy in groups

document says" Variant call_group ( String group, String method, … ) vararg". i dont know how to use vararg.

i try replac varag with argument ,but engine error.

Unfortunately the documentation page describing group usage doesn’t have a code example but this description implies that player.position should be passed inside the brackets where the … is. Are you able to try that?

There is actually an example in the docs immediately below in call_group_flags(), which is just the same call with a flags argument, but it doesn’t handle the arguments case. Maybe try:

get_tree().call_group("Enemy", "go_to_player", player.position)

If that doesn’t work, I’d look into how Callable uses bind() to hook up arguments.

One thing that’s helped me in similar situations is thinking of call_group() as a way to invoke the same method with the same arguments on every node in the group. If each node needs a different argument (for example, one of its own properties), then call_group() isn’t really the right abstraction for the job.

In those cases, I usually iterate over get_tree().get_nodes_in_group() and call the method on each node individually. It keeps the code explicit, and it’s much easier to customize the arguments or add conditional logic later. Unless every node is meant to receive identical parameters, a simple loop is often the cleaner and more flexible solution.

got it

thank u got it

thanks for your answer