New tweens are easy right?

var tween = create_tween()
@onready var pupil = $EyeA/EyeB/Pupil

So weve set up the vars for create tween and the correct path ( I dragged the Pupil node into the var statement, so path IS correct) to the node we want to tween.

func myfunc()
	tween.tween_property(pupil, "position", Vector2(18.0, 0.0), 1)

But get error....

Attempt to call function 'tween_property' in base 'null instance' on a null instance.

tween_property() is a part of the built in tween code, so its not something I haven coded yet, and null instance is an incorrect path/cant find node isnt it? - path IS correct....

You're trying to create a Tween object when node is still not ready. This won't work so tween will remain uuinitialized when you call tween.tween_property(). Check your output console and you'll see that the engine is complaining about this.

Try to create it in _ready() callback or prefix the declaration with @onready

oooo, ok, your right prefixing @onready var tween = create_tween() stops the error, but the tween HAS to go in the myfunc 😉 its a signal trigger function! I'll have to play around with this tomorrow, rather late now. Ta!

That could really do with being in the current docs, spent far too long reading through them and YT vids for something like that!!

  • xyz replied to this.

    BingBong but the tween HAS to go in the myfunc 😉

    That's irrelevant to the issue. The only thing that's important is to assign a valid Tween object to the variable tween before you call its method in myfunc().

    See below

    Keep the calls to create_tween() and tween_property() together.

    var tween: Tween = create_tween()
    tween.tween_property(pupil, "position", Vector2(18.0, 0.0), 1)

    Note: Tweens are not designed to be re-used and trying to do so results in an undefined behavior. Create a new Tween for each animation and every time you replay an animation from start. Keep in mind that Tweens start immediately, so only create a Tween when you want to start animating.

    https://docs.godotengine.org/en/4.1/classes/class_tween.html#description

    • xyz replied to this.

      DaveTheCoder Hm, I didn't know they added this limitation in v 4. Looks like a tween object gets invalidated if tweeners are not added during the same frame it got created. Right then @BingBong, disregard my previous post and create the tween in the signal handler.