The path search function enters an infinite loop

Hi guys!

I want to switch to UE4 and am now trying to repeat the function of finding a way by waypoints, it works well in Unity, but this function does not work in UE4, more precisely, it enters an loop infinite
I don’t know what the error is, maybe I am using C++ incorrectly or the methods UE4 that I call do not work as I imagine. I will be glad of any help.

#include "WaypointsPathfinding.h"
    
    #include <queue>
    #include <set>
    using namespace std;


TArray<FVector> UWaypointsPathfinding::GetPath(UWaypoint* startNode, UWaypoint* goalNode)
{
    UWaypoint* beginNode = startNode;
    set<UWaypoint*> openList;
    vector<UWaypoint*> closedList;

    openList.insert(startNode);
    startNode->previous = nullptr;
    startNode->distance = 0;

    
    while (!openList.empty())
    {
        startNode = *openList.begin();
        openList.erase(openList.begin());
        

        float dist = startNode->distance;
        closedList.push_back(startNode);
        if(&startNode == &goalNode) break;

        int l = startNode->nearest.Num();
        for (int i = 0; i < l; i++)
        {
            UWaypoint* node = startNode->nearest[i]->FindComponentByClass<UWaypoint>();
            if(find(closedList.begin(),closedList.end(),node) != closedList.end() || openList.find(node) != openList.end())
                continue;

            node->previous = startNode;
            node->distance = dist + FVector::Dist(node->GetOwner()->GetActorLocation(), startNode->GetOwner()->GetActorLocation());
            node->distance += FVector::Dist(node->GetOwner()->GetActorLocation(), goalNode->GetOwner()->GetActorLocation());
            
            openList.insert(startNode);
        }

        
    }

    // create path...
    
    return TArray<FVector>();
}

Class UWaypoint

#pragma once
    
    #include "CoreMinimal.h"
    #include "Components/ActorComponent.h"
    #include "Waypoint.generated.h"
    
    
    
    UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
    class HOVERCARSYSTEM_API UWaypoint : public UActorComponent
    {
    	GENERATED_BODY()
    
    public:
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Navigation")
    	TArray<AActor*> nearest;
    	UPROPERTY()
    	UWaypoint* previous;
    	UPROPERTY()
    	float distance;
    
    	bool operator<(const UWaypoint& right)
    	{
    		if(distance > right.distance)
    			return true;
    		else
    			return false;
    	}
    };

I also need to know this.