Invalid call. Nonexistent function 'interpolate_property' in base 'Nil'.

TheRunningStefTheRunningStef Posts: 7Member
edited September 24 in Programming

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


Tags :

Comments

  • TheRunningStefTheRunningStef Posts: 7Member

    Ahh I posted the screenshots the wrong way round :s

  • amisner2kamisner2k Posts: 8Member
    edited September 24

    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.

  • TheRunningStefTheRunningStef Posts: 7Member

    @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??

  • TwistedTwiglegTwistedTwigleg Posts: 1,608Admin

    @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:

  • TwistedTwiglegTwistedTwigleg Posts: 1,608Admin

    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)

  • TheRunningStefTheRunningStef Posts: 7Member

    @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 =)

  • TwistedTwiglegTwistedTwigleg Posts: 1,608Admin

    @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:

  • amisner2kamisner2k Posts: 8Member

    @TheRunningStef Did you get it working?

  • TheRunningStefTheRunningStef Posts: 7Member

    @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.

  • TheRunningStefTheRunningStef Posts: 7Member
    edited October 13

    @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

  • TwistedTwiglegTwistedTwigleg Posts: 1,608Admin

    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!

  • TheRunningStefTheRunningStef Posts: 7Member

    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.

  • TwistedTwiglegTwistedTwigleg Posts: 1,608Admin
    edited October 16

    @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)

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file