The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Quick question from a Godot newbie. I'm having trouble calling a method from a GDscript custom class. is a simple class I made with just a few getter methods, which is loaded by

However, I've been trying to access any of the class properties in a new Tile object, but I keep receiving a Nonexistent function error from the debugger.

Please take a look at my script files:

const TileScene = preload("res://scenes/entities/Tile.tscn")


class Tile:
    var type
    var isWall
    var sceneInstance

    func _init(type = TYPES.NULL, isWall = false):
        self.type = type
        self.isWall = isWall
        self.sceneInstance = TileScene.instance()

    func get_type():
        return self.type

    func isWall():
        return self.isWall

    func get_scene():
        return self.sceneInstance

extends TileMap

var board = null
onready var Tile = preload("res://src/")

func _ready():
    var a =
    print(a.isWall())       # <<< "Nonexistent function" error
    print(a.get_scene())    # <<< Also a "Nonexistent function" error

After running the project, the debugger displays: Invalid call. Nonexistent function 'get_scene' in base 'Reference ('.

I've been scratching my head for a while trying to figure out why I'm unable to call any of the class methods.

If anyone could help guide me in the right direction, I'd really appreciate it.

in Engine by (15 points)

1 Answer

+1 vote
Best answer

You're creating an instance of the script, not the class Tile. Try replacing

var a =


var a =
by (1,530 points)
selected by

Ah, you are absolutely correct. That was kind of a "duh" moment on my part. I didn't realize I was creating a new script instance. That makes a lot of sense, otherwise, how else would I call my enum than "Tile.TYPES". Thanks for the help!

Corrected code:

extends TileMap

var board = null
onready var Tile = preload("res://src/")

func _ready():
    var tile =
    print(tile.get_scene())    # Output: [Node2D:570]
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.