As soon as an AnimationPlayer has a key for the position of a Control node, it's GlobalPosition becomes NaN

Godot Version

v4.6.2.stable.mono.official [71f334935]

Question

I have a background in my main menu which consists of a few simple control elements, and a TextureRect near the top, which I animate using an AnimationPlayer.
However, what I noticed is that as soon as I even add a single Position keyframe to the animation player that would control where the TextureRect is, the texture rect completely disappears.

I tried to diagnose the issue by first adding some prints, like so:

public override void _PhysicsProcess(double delta)
{
    base._PhysicsProcess(delta);
    GD.Print("POS:");
    GD.Print(_backgroundTexture.Position);
    GD.Print("GLOBALPOS:");
    GD.Print(_backgroundTexture.GlobalPosition);
}

And if I don’t add the position key to the animation player, then this is the output I get:

POS:
(0, 0)
GLOBALPOS:
(0, 0)
POS:
(0, 0)
GLOBALPOS:
(0, 0)
etc...

And indeed, during this time, the texture rect is perfectly visible. However, as soon as I add a single keyframe for the position, even if it doesn’t change and it’s just 0,0, I get the following output:

POS:
(0, 0)
GLOBALPOS:
(NaN, NaN)
POS:
(0, 0)
GLOBALPOS:
(NaN, NaN)
etc...

And at that point the TextureRect is no longer visible.

Any idea why this happens?
I have no other script that modifies the TextureRect in any way, here’s the full script that currently runs:

using Godot;

namespace GameNameNDASorry.Scenes.UI.Scripts;

public partial class TestersMainMenu : Control
{
    [Export] private MarginContainer _marginContainer;
    [Export] private AnimationPlayer _backgroundAnimations;
    [Export] private TextureRect _backgroundTexture;

    public override void _Ready()
    {
        base._Ready();
        DarthFader.Instance.FadeToClear(2f);
        _backgroundAnimations.Play("initial");
    }

    public override void _PhysicsProcess(double delta)
    {
        base._PhysicsProcess(delta);
        GD.Print("POS:");
        GD.Print(_backgroundTexture.Position);
        GD.Print("GLOBALPOS:");
        GD.Print(_backgroundTexture.GlobalPosition);
    }
}

Here’s my scene tree:

Could it be because you are trying to change position of a control node?

What if changing anchors or placement within the anchors?

I’m not very good at control nodes or their properties but remember having some issues when using position and global_position on them before.

What’s wrong with changing the position of a control node? I have it’s Layout Mode set to position.

Im not sure there is anything wrong with that. As i said I’m not good with control nodes. Just a thought since i remember having issues using position with them before

I’ve modified the position of a couple of control elements before to achieve certain effects, so I highly doubt I’m not supposed to change their positions. Otherwise the property would be completely redundant.

I’m not saying it is redundant or added as a practical joke by some contributor, but that using it like this may not work.

I’m still a bit confused as to why changing a control nodes position would be “unintended”.
That would be a huge issue, as even Unity can handle that perfectly fine.

Disabling Embed Game on Next Play fixed the issue apparently.

Overall using the “Run Current scene” with Embed play is incredibly buggy and prone to breaking.

1 Like