Godot Version
4.1.1
Question
I’m new to Godot and GDScript, and was trying to instance a different scene so I can get a tilemap from it, but it returns an error.
Here is my code:
extends Area2D
var rotating
var pickcollision
@onready var limb = $Beardy/Area2D/Pickaxe
func _ready():
pickcollision = $Beardy/Area2D
# Load the scene containing the TileMap
var scene = load("res://Scenes/Themine.tscn")
# Instance the scene to access its nodes
var scene_instance = scene.instance()
# Find the TileMap node within the scene
var tilemap = find_tilemap_node(scene_instance)
pickcollision.connect("tilemap_entered", self, "_on_tilemap_entered")
# Connect the body_exited signal to the _on_body_exited method
pickcollision.connect("tilemap_exited", self, "_on_tilemap_exited")
func find_tilemap_node(node):
# Recursive function to find the TileMap node within the scene
if node is TileMap:
return node
func _on_body_entered(tilemap):
# Called when the CollisionShape2D enters another physics body
print("Collision entered with", tilemap.name)
rotating = false
pickcollision.set_disabled(false)
limb.visible = true
func _on_body_exited(tilemap):
# Called when the CollisionShape2D exits another physics body
print("Collision exited with", tilemap.name)
rotating = true
pickcollision.set_disabled(false)
limb.visible = true;
And it returned the error:
Invalid call. Nonexistent function 'instance' in base 'PackedScene'.