Can anyone explain why my function calls appear to be out of order?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Rhombazoid

I am working on a tactical RPG game, and I thought it would be a good idea to add a health bar to the selected unit and all of the units affected by an attack. So far, it’s working great. I just need a way to remove the health bars from units that are no longer involved in combat. I thought, Easy, I’ll just use a group call to hide all the health bars when we select a new one.

func attempt_unit_selection(grid_pos: Vector2) -> void:
	active_unit = null
	for unit in unit_positions:
		if unit_positions[unit] == grid_pos:
			active_unit = unit
	get_tree().call_group('units','hide_health_bar')
	$UnitInfo.hide()
	if active_unit != null:
		$UnitInfo.display(active_unit)
		active_unit.show_health_bar()

Except, it looks like the get_tree().call_group() is occuring after the final line in this code. Any ideas?

Enemy1 showing health!
Enemy3 hiding health!
Enemy1 hiding health!
Enemy2 hiding health!

It’s worth noting that the $UnitInfo calls that show more detailed information about the units is showing and hiding as expected.

:bust_in_silhouette: Reply From: skysphr

From the docs:

Note: call_group will always call methods with an one-frame delay, in
a way similar to Object.call_deferred. To call methods immediately,
use call_group_flags with the GROUP_CALL_REALTIME flag.

Thanks! That would be the problem. Solved.

Rhombazoid | 2022-02-12 23:24