Return Self returns Nil?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fruktus

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.

:bust_in_silhouette: Reply From: fruktus

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