Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Forward | |
Old Version | Published before Godot 3 was released. |
Is it possible to grab all nodes from another scene that are in a group? I’m basically trying to find all nodes in a group called “Enemy” in the world scene. Once they’re all found I want to then choose a random one and grab its texture for UI sprite.
The errors I’m getting:
Attempt to call function ‘get_nodes_in_group’ in base ‘null instance’ on a null instance.
It’s also saying that world.tscn isn’t being found. So maybe I’m not under standing how to grab nodes from another scene correctly?
Can anyone point me in the right direction or tell me where I’m going wrong? I’m new to GODOT.
extends CanvasLayer
onready var ammobar = get_node("TextureProgress")
onready var bounty = get_node("Panel/Bounty")
# class member variables go here, for example:
# var a = 2
# var b = "textvar"
var bounty_Ended = true
onready var enemies = get_node("res://world.tscn").get_nodes_in_group("Enemy")
func update_HUD():
var amount = get_parent().ammo
ammobar.set_val(amount)
func update_Bounty():
if(bounty_Ended == true):
bounty.Texture = enemies.rfind(rand_range(1,5))
bounty_Ended = false
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
update_HUD()
update_Bounty()