TUnion use in while loop causing memory leak

There’s a bug in the copy constructor, which I think might be part of my problem. Not sure, if there are other bugs involved as well.

TArray<FName> UBaseDialogue::GetBranch()
{
    BranchTypes u = dialogues.Find(id)->branch;

    FName next;
    while(u.HasSubtype<Condition>())
    {
        next = u.GetSubtype<Condition>()();
        u = dialogues.Find(next)->branch; // this line causes the crash
    }

    NextFragment(next);
    return u.GetSubtype<BranchValues>();
}

I tried using BranchTypes &u = dialogues.Find(id)->Branch, but that didn’t seem to help. I tried using debug logs to see what’s going on, but those just prevent the crash from happening in the first place. How could I go about making this while loop not lead to a crash? Would the move constructor be the correct approach?

Well, I found a solution. Not sure if this is the most efficient solution, but it stops the editor from crashing. Looks like I was MoveTemp was the wrong method to call for the move constructor I had to use Move.

TArray<FName> UBaseDialogue::GetBranch()
{
    BranchTypes u;
    Move(u, dialogues.Find(id)->branch);

    FName next;
    while(u.HasSubtype<Condition>())
    {
        next = u.GetSubtype<Condition>()();
        Move(u,dialogues.Find(next)->branch);
    }

    NextFragment(next);
    return u.GetSubtype<BranchValues>();
}