Line Trace object is flying to Camera

Hello Guys! I have a problem with Line trace. When i activate it object is flying to camera component. It seems like Cursor somehow hits the camera and camera location becames end location of the trace, but i don’t know how to fix this. Actually I tried to change ECC_Visibility to ECC_Camera. or pawn. but it does not helps. Also i tried do smth with objects collision, and in some ways it works, but for objects of one class (for example desk) merges (collision is not working, and i really need this collision for objects).
On this gif you can actually see what is going on: https://giphy.com/gifs/linetrace-xUA7aPWCtONNCKa15S
Code of my Line trace:

void AObjectTemplate::PickupLineTrace() {
	FHitResult *HitResultTrace = new FHitResult();
	FVector StartLocation;
	FVector EndLocation;
	if (MyPC) {
		FVector WorldMouseLocation;
		FVector WorldMouseDirection;
		UGameplayStatics::GetPlayerController(GetWorld(), 0)->DeprojectMousePositionToWorld(WorldMouseLocation, WorldMouseDirection);
		WorldMouseDirection = WorldMouseDirection * 10000.0f;
		StartLocation = WorldMouseLocation;
		EndLocation = WorldMouseLocation + WorldMouseDirection;
		FCollisionQueryParams TraceParams;
		UE_LOG(LogTemp, Warning, TEXT("before line trace"));
		if (GetWorld()->LineTraceSingleByChannel(*HitResultTrace, StartLocation, EndLocation, ECC_Camera, TraceParams)) {
				SetActorLocation(HitResultTrace->Location);
			}
			UE_LOG(LogTemp, Warning, TEXT("after line trace"));
		 }
		
	}

Code of camera component (in other class):

 ACursorPawn::ACursorPawn()
    {
    	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    	PrimaryActorTick.bCanEverTick = true;
    	AutoPossessPlayer = EAutoReceiveInput::Player0;
    	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
    	//
    	MyCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("GameCamera"));
    	MyCamera->SetupAttachment(RootComponent);
    	MyCamera->SetRelativeRotation(FRotator(-90.0f, 0.0f, 0.0f));
    	CameraPanSpeed = -20.0f;
    	CameraRotationSpeed = -10.0f;
    	ZoomSpeed = -150.0f;
}

Do i get it right, that your trace-code is inside the object you are tracing ?

I think it behaves exactly like you ordered it to.
In line 15 you tell the object to move (SetActorLocation(…)) to the hitlocation of your trace.
So it moves by the difference of the objectpivot to the hitlocation on the collisionprimitive every tick.

Simple here is what you do currently:

You shoot a trace from your Camera to the Mouse direction.

If you hit something you tell your object to move to that location (line 15)

The thing you hitting is your “Own” Object so it moves where you hit it with the mouse.

The thing you want todo instead is ignore your “Own”(this) Object so it never gets hit by the trace. You can add Actors to ignore to FCollisionQueryParams. Theres a wiki around so I dont go into detail here. Heres the link A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums

Thank you for reply! I thought that it is connected with camera, but with your help i understood that static mesh getting up because trace hits it. (before it i tried to add to ignore actors camera :smiley: ). But now it works! Thank you a lot. Maybe you saved my exam work!:slight_smile:

Thx for reply, you helped me a lot! Now it works. My apologize!