0 votes

In one of my classes, I've created a function that returns self.
Does anybody know of a way define the return type with static typing?
I know this can be done if using class_name, but I want to keep the global namespace clean.

# MyClass.gd
extends Node


func self_returning_func(): # -> MyClass
    return self
in Engine by (64 points)

There are issues open about it:
https://github.com/godotengine/godot/issues/25252
https://github.com/godotengine/godot/issues/21461

It will likely get worked on soon, vnen is now full time on GDScript.

1 Answer

+2 votes

I think, if you are not using class_name, Godot will consider this object as Node. Or anything you extends from.

"MyClass" actually does not exist before declaring it as class_name or class.

by (22 points)
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.