This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello.
TL;DR I have a statement in gdscript: return self, which seems to return Nil. What am I doing wrong?

Long version:
I have a script which is not extending a Node (it's a reference) which I am instancing. It contains a method that is supposed to return a reference to itself, so that I can assign it to multiple other objects, but after calling it and trying to use it I get Nil reference error, which leads me to believe that returning self either does not work as I expect or that I need to change something. Can you please explain how I should tackle this? I could return new instance (probably) but in some cases I'd like to share a single one among few objects.

Godot version 3.2.2
in Engine by (18 points)

1 Answer

0 votes

Nevermind, I had many scripts set up like that and in one I missed return statement. Returning self works as expected.

by (18 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.