0 votes
func draw():

class T:
    func go():

func _ready():
    var t = T.new()

How do I do this?
It's not in the parent... in Python draw() would be in global scope so this would work.

in Engine by (12 points)

1 Answer

0 votes

Please read

extends Node 

class_name MyClass

func draw()

extends MyClass  # or extends "res://path/to/MyClass.gd"

func _ready():
by (288 points)


How do I access things from my inner class?

I don't think it's working the same as your python example

This is not working like that in gdscript

The inner class do not inherit from the main, so you have to declare variable and function, the same way you're doing for any classes.

How would I pass in the 'outer' class in? It has no definition or name?


FFS - OMG. It's just like Python, there's a self keyword:

extends MeshInstance

func draw():

class T:
    func go(parent):

func _ready():
    var t = T.new()

This works. Thanks for the help and the hints. I gues because class T method go doesn't have a self parameter (as Python would have) I assumed self wasn't a keyword.

Thanks Unrealcloud 1 == you're a flipping legend! I owe you a pint.


I think parent is a dirty variable name, maybe owner would be better? Hm... Godot does present you with some weird decision - lol. Maybe this should just be illegal code?

I think for the moment this is not a possible.
There is an github issue : https://github.com/godotengine/godot/issues/4472

Uhm ok, but this is working but nothing to do with inner class and outter class .
And actually class T method have a self parameter .

Anyway I'm happy you find a way

EDIT : Well parent is a bad name, because usually parent refer to parent Node - Child Node. You can acces to a parent in the node tree by get_parent(), but whatever.

But what really distrub me is that your inner class for the moment ( godot 3.2.2), can't acces function out of scope soooo, class T it's just an object, you could literaly create a new class in another file, if you give a function like func go(parent): parent.draw(), well you just applied command pattern design, it could be

func go(receiver):

same stuff:

So why use inner class ^^ . Anyway not my jam, but if it works for you , fine for me

Edit 2 : As described here : https://stackoverflow.com/questions/2024566/how-to-access-outer-class-from-an-inner-class

So your first statement It's not in the parent... in Python draw() would be in global scope so this would work. is wrong. I presume in python the key word self is passing . But as you can try in python .

def draw():
  print("Hello UnRealCloud1")

class T:
  def go(self):

t = T()


will return an error .

But thx to point it out, I have a better view of how inner class work in general

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.