I keep getting this error when I'm trying to tween some movement in my game. Please help - I'm new to Godot so it's probably something really stupid.

I've attached a screenshot of the code here:

And here's one of the node tree:

Thanks in advance, TheRunningStef

Well that error definitely means that your tween instance is Nil for some reason although given the code you've shown I don't see why, because the onready var should make it get the node in _ready as expected and your path to it looks correct.

As a troubleshooting step, I would use get_node("Tween") on the line where you're using it just to see if it still returns Nil.

@amisner2k said: Well that error definitely means that your tween instance is Nil for some reason although given the code you've shown I don't see why, because the onready var should make it get the node in _ready as expected and your path to it looks correct.

As a troubleshooting step, I would use get_node("Tween") on the line where you're using it just to see if it still returns Nil.

Ok I tried that but it still comes up with an error, a different one: "Attempt to call function 'interpolate_property' in base 'null instance' on a null instance."

What is going on??

@TheRunningStef said: Ahh I posted the screenshots the wrong way round :s

I edited your post and now they should be in the correct order. :smile:

It means that you are trying to call a function, interpolate_property on a class that does not have that function, and the class is of type null.

In other words, this means that the get_node("Tween") function call is either not working, or it is not being assigned to the correct value. Try adding this right before line 34 in the screenshot:

tween = get_node("Tween")
print ("Tween variable is set to: ", tween)

and see what the console prints. It should (hopefully) print something like Tween variable is set to: Tween. (Side note: Welcome to the forums)

@TwistedTwigleg said: It means that you are trying to call a function, interpolate_property on a class that does not have that function, and the class is of type null.

In other words, this means that the get_node("Tween") function call is either not working, or it is not being assigned to the correct value. Try adding this right before line 34 in the screenshot:

tween = get_node("Tween")
print ("Tween variable is set to: ", tween)

and see what the console prints. It should (hopefully) print something like Tween variable is set to: Tween. (Side note: Welcome to the forums)

When I printed just the variable it gives this: "[Tween:1306]"

Also thanks =)

@TheRunningStef said: When I printed just the variable it gives this: "[Tween:1306]"

Hmm, so that means the get_node call isn't necessarily the issue. What error does the debugger show with the changes in the code? Also, which line is the error on? I would assume it is on the line posted in the screenshot, line 34.

Also thanks :smiley:

No problem :smile:

13 days later

@TheRunningStef Did you get it working?

5 days later

@amisner2k said: @TheRunningStef Did you get it working?

No, I really dont know what's going on :s, if I get it to work, I will share it with you guys.

@TwistedTwigleg said:

@TheRunningStef said: When I printed just the variable it gives this: "[Tween:1306]"

Hmm, so that means the get_node call isn't necessarily the issue. What error does the debugger show with the changes in the code? Also, which line is the error on? I would assume it is on the line posted in the screenshot, line 34.

Also thanks :smiley:

No problem :smile:

Ok so I checked the debugger and this is what it returned:

I'm guessing it's somehow relating to the other functions? Please help.

EDIT: So I tried moving the interpolate_property() function into the _ready() function and guess what? It worked! I'm guessing it's something to do with the function being called within a function within a function. Im not sure if this is a general error or is just my computer being bad. If u lot have any idea how to fix this please let me know :D

Hard to say what is happening without seeing the entire code file and/or the project. Debugging errors like this can be tricky because a number of things could be causing the issue.

That said, since the function works in _ready, the issue might be that the Tween node is moved/deleted/etc before the code could be called. The error in the debugger mentions that the reason the code is not working is because it cannot find a node with the name "Tween", meaning the "Tween" node isn't there or uses a different name. Apparently the error is caused by line 34 in Player.gd, so maybe look and see if something there changes the "Tween" node? Outside of that, I don't really know, sorry!

I don't know what's wrong because I tried putting add_child(Tween.new()) before the animation code, but it still doesnt work, suggesting that it's not just renamed or deleted the Tween node.

@TheRunningStef said: I don't know what's wrong because I tried putting add_child(Tween.new()) before the animation code, but it still doesnt work, suggesting that it's not just renamed or deleted the Tween node.

add_child(Tween.new()) will instance/create a new node, which shouldn't be necessary if you already have a Tween node in the scene.

The newly instanced Tween node will have an auto generated name, something like Node#5021, so you'll likely want to keep a reference to it if you want to use it elsewhere in the script. If you want to create the Tween node from code, then you'll probably want to instance/create the tween node using code like this (untested):

var tween_node
func _ready():
	# Spawn a new Tween node
	tween_node = Tween.new()
	tween_node.name = "Instanced_Tween"
	add_child(tween_node)
func _process(delta):
	if (tween_node.is_active() == false):
		tween_node.interpolate_property(self, "position", Vector2(0, 0), Vector2(10, 10), 4, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)

I'm not sure if that is causing the issue, but it might be something to look into. That said, if you already have a Tween node in the scene and you can access said Tween node in _ready using get_node, then the issue might be something else is overriding the variable and/or getting in the way when you try to retrieve the Tween node.

(My apologizes in advance for any mistakes, I was writing this in a bit of a hurry)

6 months later

Hi I had to take a bit of a break from programming. Basically, I think I have worked out why the error is happening but I'm not sure how to fix it. So the attack() function is actually called in a separate script, attached to the attack button, so that when it is pressed the player will attack.

func onclick() :
	...
	player.attack(enemyNode)

I think when the Tween node is called, Godot searches for it as a child of the attack button. How can I make it so that it calls it for the player?

I finally fixed it! Basically I was calling the function from an instantiated player script. I changed it so it is called from the player node and it works. I feel incredibly stupid now :#

@TheRunningStef said: I finally fixed it! Basically I was calling the function from an instantiated player script. I changed it so it is called from the player node and it works. I feel incredibly stupid now :#

Great! I'm glad you got it working! Don't worry about feeling "stupid", it is an easy mistake and these types of mistakes happen to all of us. :smile:

3 years later