Question

Im having problems with something, Im not sure if its my understanding of pointers, or Unreal itself. Here is my code

TArray<Anode> nodes;
TActorIterator<Anode> ActorItr = TActorIterator< Anode >(GetWorld());

while (ActorItr) //Go through EVERY Node and check distance
{
    if (this->GetUniqueID() != ActorItr->GetUniqueID())
    {

        //Check Distance
        if (FVector::DistSquared(this->GetActorLocation(), ActorItr->GetActorLocation()) < 262144) //Check the distance between the two nodes.
        {
            Anode node = ActorItr;
            //Anode* node = Cast<Anode>(*ActorItr);

            nodes.Add(node); //Calls a error because
            //cannot convert from 'TActorIterator<Anode>' to 'Anode'

        }
        }
    }
}

So my issue is i cannot convert the Actor Iterator to my TArray, and i have played around with de-referencing etc, i got it to compile but crash at run-time. Thanks!

Edit: For clarity

i have tried

Anode node = *ActorItr;

but got a error C2440: 'initializing' : cannot convert from 'Anode *' to 'Anode'. I then tried

Anode *node = *ActorItr;
nodes.Add(*node); 

It compiled but created a run time error with unhanded memory or something, i think this is because its just handing the pointer to the TArray without handling the issue (is that right?). I understand the concept i feel, but not the syntax.

Was it helpful?

Solution

The actor iterator is not an actor, so direct assignment doesn't make any sense. Try dereferencing the iterator (Anode* node = *ActorItr;), that operator should be overloaded to return the current element of the iteration, i.e. the node you want to use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top