How to convert string to method

Godot Version

4.2

Question

I am trying to be able to convert a string to a object

var enemy2 = enemy.instantiate()

add_child(enemy2)
enemy2.position = "$Enemt_Spawn_" + str(amt_of_spawns).position
test = rng.randi_range(1,amt_of_spawns)

I want “$Enemt_Spawn_” + str(amt_of_spawns) to be able to turn to a method so i can teleport the enemy to that location

As far as I know, you cant append to a $GetNode using strings and is just a script exclusive thing. Though you can use the get_node() function which is what $ is shorthand for.

For your case you can just do:

enemy2.position = get_node("Enemt_Spawn_" + str(amt_of_spawns)).position
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.