Self.position = Vector2, not working

Godot Version

v4.2.2

Question

@export var path : Array[Vector2] = []

var nextNodeIndex : int = 1

@onready var lastNode : Vector2 = path[0]
@onready var nextNode : Vector2 = path[1]

func _process(delta):
  if self.position == nextNode:
    var srtMidEnd : int = 0 #start:-1 , mid:0, end:1
    if nextNodeIndex == 0:
      srtMidEnd = -1
    if nextNodeIndex == path.size()-1:
      srtMidEnd = 1
        
    
  if srtMidEnd == 1:
    print("test1")
    nextNodeIndex = 1
                    
    lastNode = path[0]
    nextNode = path[1]
                    
    self.position = lastNode
                    
    print(lastNode)
    print(nextNode)
    print(self.position)
  else:
    nextNodeIndex += 1

    lastNode = nextNode
    nextNode = path[nextNodeIndex]

  self.position = self.position.move_toward(nextNode, moveSpeed * delta)

This code is trying to make a platform move along a path then at the end go back to the start and do it again. the platform is moving as it should however when it reaches the end it doesn’t work properly.

The line with self.position = lastNode doesn’t seem to be working, the platform does move towards the 2nd node (as it should) but it doesn’t set its position to the 1st node.

ive added output from prints as an attachment.
image

not sure what is happening here. thanks for any help!

ive been paying around and managed to reproduce the bug with this code and setup:

extends AnimatableBody2D

@export var moveSpeed : float = 40

var pos1 : Vector2 = Vector2(50, 50)
var pos2 : Vector2

func _ready():
    self.position = pos1

func _process(delta):
    self.position = self.position.move_toward(pos2, moveSpeed * delta)
    
    pos2.x += 50
    pos2.y += 50

image

solution:

make sure the position is being updated in _physics_process() not _process()

code:

@export var path : Array[Vector2] = []

var nextNodeIndex : int = 1

@onready var lastNode : Vector2 = path[0]
@onready var nextNode : Vector2 = path[1]

func _physics_process(delta):
  if self.position == nextNode:
    var srtMidEnd : int = 0 #start:-1 , mid:0, end:1
    if nextNodeIndex == 0:
      srtMidEnd = -1
    if nextNodeIndex == path.size()-1:
      srtMidEnd = 1
        
    
  if srtMidEnd == 1:
    print("test1")
    nextNodeIndex = 1
                    
    lastNode = path[0]
    nextNode = path[1]
                    
    self.position = lastNode
                    
    print(lastNode)
    print(nextNode)
    print(self.position)
  else:
    nextNodeIndex += 1

    lastNode = nextNode
    nextNode = path[nextNodeIndex]

  self.position = self.position.move_toward(nextNode, moveSpeed * delta)

Thanks, I am marking this as solved.