After following the instructions on how to fix the flying tanks when you start via the main menu I had different issues (jittering AI tanks) so I had a look online and found this, which allows you to have the collision meshes on the tank tracks, body, turret and barrel, without issues.
After revisiting this, I think that is actually just ignoring collision with everything, I’ve changed the way I’m doing it now, so it’s all done in a C++ Initialise method. I’ve set all components in the tank blueprint to NoCollision.
void ATank::Initialise(UTankBarrel* BarrelReference, UTankTurret* TurretReference, UTankTrack* LeftTrackReference, UTankTrack* RightTrackReference, UTankMovementComponent* MovementComponentToSet)
{
AimingComponent->SetBarrelReference(BarrelReference);
Barrel = BarrelReference;
AimingComponent->SetTurretReference(TurretReference);
LeftTrack = LeftTrackReference;
RightTrack = RightTrackReference;
MovementComponent = MovementComponentToSet;
MovementComponent->Initialise(LeftTrack, RightTrack);
TArray<UPrimitiveComponent*> MyComponents;
MyComponents.Add(Barrel);
MyComponents.Add(TurretReference);
MyComponents.Add(LeftTrack);
MyComponents.Add(RightTrack);
//tank body \/
MyComponents.Add(Cast<UPrimitiveComponent>(GetRootComponent()));
TArray<AActor*> IgnoreActors;
IgnoreActors.Add(GetOwner());
for (int i = 0; i < MyComponents.Num(); i++)
{
MyComponents[i]->MoveIgnoreComponents = MyComponents;
MyComponents[i]->MoveIgnoreActors = IgnoreActors;
}
for (int i = 0; i < MyComponents.Num(); i++)
{
MyComponents[i]->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block);
MyComponents[i]->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
MyComponents[i]->SetCollisionObjectType(ECollisionChannel::ECC_WorldDynamic);
}
UE_LOG(LogTemp, Warning, TEXT("Tank Initialisation completed"))
}
Which makes BeginPlay blueprint much simpler!