Collision issue.

Hello,

I have a bunch of instances static meshes being created each of these objects should have collision on them.
However, when I click on them they don’t trigger a hit (all the time)

This is my actor:



AMStar::AMStar()
{
PrimaryActorTick.bCanEverTick = true;
Star = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("Star"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> StarAsset(TEXT("/Game/Levels/Galaxy/GalaxyStarSphere"));
static ConstructorHelpers::FObjectFinder<UMaterial> MaterialAsset(TEXT("Material'/Game/Levels/Galaxy/MMaterial'"));

if (MaterialAsset.Succeeded())
{
Material = MaterialAsset.Object;

if (StarAsset.Succeeded())
{
Star->SetMaterial(0, Material);
Star->SetStaticMesh(StarAsset.Object);
Star->SetRelativeLocation(FVector(0.0f));
Star->Mobility = EComponentMobility::Static;
Star->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
Star->SetCollisionObjectType(ECollisionChannel::ECC_Visibility);
Star->BodyInstance.SetCollisionProfileName("StarCollision");
Star->CastShadow = false;

}
}

RootComponent = Star;
}


This is the method I’m using to check for a “hit”



FHitResult HitResult;
AMainPlayerController* controller = Cast<AMainPlayerController>(GetController());

FVector worldLocation, worldDirection;

controller->DeprojectMousePositionToWorld(worldLocation, worldDirection);

UWorld* const World = GetWorld();
if (World != NULL)
{

const auto startLocation = worldLocation;
const auto targetLocation = worldLocation + worldDirection * 100000;

FCollisionQueryParams queryParams;
const FName myTraceTag("MyTraceTag");
World->DebugDrawTraceTag = myTraceTag;
queryParams.TraceTag = myTraceTag;

FCollisionResponseParams collisionParams;

World->LineTraceSingleByChannel(HitResult, startLocation, targetLocation, ECollisionChannel::ECC_Visibility, queryParams, collisionParams);

if (HitResult.bBlockingHit)
{
UE_LOG(LogTemp, Log, TEXT("I have been hit"));
}

}


I think there is something wrong with the line trace, this is me clicking the dead centre of the sphere.

I’m sure I have done something stupid, any help would be appreciated.

Many thanks

I’m wondering if its something to do with my pawn coordinates?
When I spawn at 0,0,0 the line trace seems to work fine. The further I get out the more it seems to act weird.

51505888.0, 51351044.0, 448660.90625