In my project, several “planets” are connected to each other via “links,” which are determined based on up to three pointers in each planet. Lines representing the links should be drawn at runtime. My current code correctly prints out the X location of each planet (for verification) but does not draw the lines for the links. How can I draw the lines linking the systems as specified by the three link pointers? I’m very new to UE4 and have been reading on this subject for hours with no progress.
void ASystemLinks::BeginPlay()
{
Super::BeginPlay();
UGameplayStatics::GetAllActorsOfClass(GetWorld(), APlanet_Base::StaticClass(), FoundActors);
for (int k = 0; k < FoundActors.Num(); k++) {
auto element = FoundActors[k];
APlanet_Base* planet = Cast<APlanet_Base>(element);
FVector planetLoc = planet->GetActorTransform().GetTranslation();
//this method may draw duplicate lines
if (planet->link1 != nullptr) {
FVector linkLoc = planet->link1->GetActorTransform().GetTranslation();
GetWorld()->LineBatcher->DrawLine(planetLoc, linkLoc, FColor(255,255,255), SDPG_World, 100.f, 0);
UE_LOG(LogTemp, Warning, TEXT("%d"), (int)linkLoc.X);
}
if (planet->link2 != nullptr) {
FVector linkLoc = planet->link2->GetActorTransform().GetTranslation();
GetWorld()->LineBatcher->DrawLine(planetLoc, linkLoc, FColor(255, 255, 255), SDPG_World, 100.f, 0);
UE_LOG(LogTemp, Warning, TEXT("%d"), (int)linkLoc.X);
}
if (planet->link3 != nullptr) {
FVector linkLoc = planet->link3->GetActorTransform().GetTranslation();
GetWorld()->LineBatcher->DrawLine(planetLoc, linkLoc, FColor(255, 255, 255), SDPG_World, 100.f, 0);
UE_LOG(LogTemp, Warning, TEXT("%d"), (int)linkLoc.X);
}
}
}