Hello world again,

I find myself struggle on something with variables.

I have a sprite in my scene, and I am unsure of what variable to use to declare this as to access all parts of the sprite. I have snippets of what I am referencing

And yes, I am aware that object does not work for that.

Again, I appreciate all help! Thank you.

Awesome! I thank you sincerely, I did not know this was a thing. Are there any other variable types like this?

Actually I am getting a new error now.

"A field initializer cannot reference the non-static field, method, or property 'Node.GetNode<Sprite>(NodePath)'"

Not sure what is exactly wrong, I thank you for the help this far by the way.

@somecreep32 said: Actually I am getting a new error now.

"A field initializer cannot reference the non-static field, method, or property 'Node.GetNode<Sprite>(NodePath)'"

(Images removed to save space)

Not sure what is exactly wrong, I thank you for the help this far by the way.

You cannot get a node in the definition for the variable. You will need to define the variable as a Sprite, and then call get node later in a function like _Ready. For example:

public class Panel : Godot.Panel {
	# other code here...
	Sprite mySprite;
	# other code here...
	
	public override void _Ready() {
		mySprite = GetNode<Sprite>("Cookie");
		# other code here...
	}
}

Then you can use it as expected.

Is this only limited to "_Ready"? Or am I able to set this anywhere?

Actually disregard that last comment. Many thanks guys!

Changed the topic type to a question and removed the superfluous bit from the title. You can now mark the appropriate post as an accepted answer. Note that there is no need to reject the other posts, it's just possible to accept multiple posts.

2 years later