Is there a way to reference a current node in C#

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

Hi I’m using Godot 3.5 Mono version and I am practicing coding using this C# language. But I keep getting errors of System.NullReferenceException: Object reference not set to an instance of an object.

I usedGetParent(), GetNode() and Name on this one. I give up after searching for related problems for hours now.

Is there any way to reference them like self in GDScript?

:bust_in_silhouette: Reply From: jgodfrey

I believe the the C# equivalent of gdscript’s self is this.

It’s still getting me the same error. I think this only passed the script or class or something; not the actual object itself. My code is this:

private void OnRubbishEntered(Player body) { body.AddRubbishToQueue(GetParent<Node>.GetNode<Rubbish>(this.Name)); }
I tested it out using GD.Print to see if it outputs the object but only the name not the actual object itself. So is there any way I can reference it as an object?

rcbit | 2023-02-06 01:04