I have some troubles with tank movements and using debug find out that function TArray<ASprungWheel*> UTankTrack::GetWheels() const always return 0!
Here is my implementation:
TArray<ASprungWheel*> UTankTrack::GetWheels() const{ //-- error was here
TArray<ASprungWheel*> ResultArray;
TArray<USceneComponent*> Children;
GetChildrenComponents(true, Children);
int i(0);
for (USceneComponent* Child : Children)
{
auto SpawnPointChild = Cast<USpawnPoint>(Child);
if (!SpawnPointChild) continue;
AActor* SpawnedChild = SpawnPointChild->GetSpawnedActor();
//UE_LOG(LogTemp, Warning, TEXT("Actors names %s"),*SpawnedChild->GetName()); // if get name = crash?!
//if(!ensure( *SpawnedChild->GetName() )){ continue;}
auto name = Child->GetName();//*SpawnedChild->GetName();
UE_LOG(LogTemp, Warning, TEXT("Track child %s"),*name);
//auto SprungWheel = Cast<ASprungWheel>(SpawnedChild);
//if (!SprungWheel) continue;
ASprungWheel* SprungWheel = Cast<ASprungWheel>(Child);
if (!SprungWheel) continue;
i++;
ResultArray.Add(SprungWheel);
}
UE_LOG(LogTemp, Warning, TEXT("get wheels must return %i"),i);
return ResultArray;
}
the resulting output is:
LogTemp: Warning: get wheels must return 0
LogTemp: Warning: Track child SpawnPoint3
LogTemp: Warning: Track child SpawnPoint2
LogTemp: Warning: get wheels must return 0
LogTemp: Warning: Track child SpawnPoint
LogTemp: Warning: Track child SpawnPoint1
LogTemp: Warning: get wheels must return 0
LogTemp: Warning: Track child SpawnPoint3
LogTemp: Warning: Track child SpawnPoint2
LogTemp: Warning: get wheels must return 0
LogTemp: Warning: Track child SpawnPoint
LogTemp: Warning: Track child SpawnPoint1
LogTemp: Warning: get wheels must return 0