Endless Runner world generation stops at certain point.

Hey, I am making a 2d (Verticle) endless runner game, following a tutorial. Now I ran into a problem that my endless level generation stops when I go to high (when i go 3000 higher from start). It doesn’t have anything to do with worldorigin, I think it must be in the script somewhere.
Here is a video of what happens zoomed out: Imgur: The magic of the Internet
And here is the script:
private const float PLAYER_DISTANCE_SPAWN_LEVEL_PART = 250f;

    [SerializeField] private List<Transform> levelPartList;
    [SerializeField] private Transform levelPart_Start;
    [SerializeField] private Player player;

    private Vector3 lastEndPosition;
    private void Awake()
    {

        lastEndPosition = levelPart_Start.Find("EndPosition").position;

        int startingSpawnLevelParts = 20;
        for (int i = 0; i < startingSpawnLevelParts; i++)
        {
            SpawnLevelPart();
        }


    }

    private void Update()
    {
        if (Vector3.Distance(player.transform.position, lastEndPosition) < PLAYER_DISTANCE_SPAWN_LEVEL_PART)
        {
            SpawnLevelPart();
        }
    }

    private void SpawnLevelPart()
    {
        Transform chosenLevelPart = levelPartList[Random.Range(0, levelPartList.Count)];
        Transform lastLevelPartTransform = SpawnLevelPart(chosenLevelPart, lastEndPosition);
        lastEndPosition = lastLevelPartTransform.Find("EndPosition").position;
    }


    private Transform SpawnLevelPart(Transform levelPart, Vector3 spawnPosition)
    {
        Transform levelPartTransform = Instantiate(levelPart, spawnPosition, Quaternion.identity);
        return levelPartTransform;
    }

It’s quite hard to tell from the video but it looks like the player slowly “catches up” to the new level parts and eventually overtakes them, in which case Vector3.Distance(player.transform.position, lastEndPosition) would start to increase again.

I don’t know how your player controller looks, but is it possible you’re moving the player in FixedUpdate, in which case it might be running more frequently than your level generation?

If you need to spawn more than one levelPart per frame your code will not work.

Try

private void Update()
{
    while(Vector3.Distance(player.transform.position, lastEndPosition)<PLAYER_DISTANCE_SPAWN_LEVEL_PART)
    {
        SpawnLevelPart();
    }
}

But Vector3.Distance is maybe also not correct to do, since it will measure the the distance regardless of the player is in front of the level part or behind it, that will cause you to stop adding level parts when too much in front like what is seen in your clip.