# Unreal crash when trying to line trace with camera

**URL:** <https://forums.unrealengine.com/t/unreal-crash-when-trying-to-line-trace-with-camera/614241>\
**Category:** AI\
**Tags:** unreal-engine, UE5-0, CPP, question\
**Created:** [July 26, 2022, 12:38am UTC](https://forums.unrealengine.com/t/unreal-crash-when-trying-to-line-trace-with-camera/614241 "2022-07-26T00:38:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shotty46290](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@shotty46290](https://forums.unrealengine.com/u/shotty46290)\
**Post date:** [July 26, 2022, 12:38am UTC](https://forums.unrealengine.com/t/unreal-crash-when-trying-to-line-trace-with-camera/614241/1 "2022-07-26T00:38:33Z")

</div>

When I try to get my camera for my line trace the engine crashes with an access violation why is this? If I try to line trace from the mesh or the spring arm it goes up and to the right in a weird direction.

 ![crash](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/e/f/eeff5599afaf858eeb73726ffb8a94aa89c1f8d1.jpeg)

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [July 26, 2022, 4:40am UTC](https://forums.unrealengine.com/t/unreal-crash-when-trying-to-line-trace-with-camera/614241/2 "2022-07-26T04:40:02Z")

</div>

Please copy your code using  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/5/e/75ebd389cd4a44dc413c9629355424b1a69fb25f.png)  
Can’t read as it is.

---

<div class="post-metadata">

**Author:** ![shotty46290](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@shotty46290](https://forums.unrealengine.com/u/shotty46290)\
**Post date:** [July 26, 2022, 7:19am UTC](https://forums.unrealengine.com/t/unreal-crash-when-trying-to-line-trace-with-camera/614241/3 "2022-07-26T07:19:32Z")

</div>

```auto
FVector Start = PlayerCamera->GetComponentLocation();
	FVector End = PlayerCamera->GetComponentLocation().ForwardVector + 1500.f;
	FCollisionQueryParams Params;
	Params.AddIgnoredActor(this);
	DrawDebugLine(GetWorld(), Start, End, FColor(255, 0, 0, 1), false, 10.f, 2, 20);
	return GetWorld()->LineTraceSingleByChannel(Hit, Start, End, ECollisionChannel::ECC_Camera, Params);

```

---

<div class="post-metadata">

**Author:** ![Linqen](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/linqen/32/924597_2.png) [@Linqen](https://forums.unrealengine.com/u/Linqen)\
**Post date:** [July 26, 2022, 8:23am UTC](https://forums.unrealengine.com/t/unreal-crash-when-trying-to-line-trace-with-camera/614241/4 "2022-07-26T08:23:59Z")

</div>

For how little I can see in the crash callstack, looks like PlayerCamera is nullptr.

If you could also copy your callstack, that would be great, but check and be sure PlayerCamera has a valid value.

---

<div class="post-metadata">

**Author:** ![shotty46290](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@shotty46290](https://forums.unrealengine.com/u/shotty46290)\
**Post date:** [July 26, 2022, 6:00pm UTC](https://forums.unrealengine.com/t/unreal-crash-when-trying-to-line-trace-with-camera/614241/5 "2022-07-26T18:00:40Z")

</div>

here is my constructor where I create the camera

```auto
ASurvivalCharacter::ASurvivalCharacter()
{
 	// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	TurnRateGamepad = 45.f;

	SurvivalStatsComp = CreateDefaultSubobject<USurvivalStatsComponent>("Survival Stats Component");
	PlayerInventory = CreateDefaultSubobject<UPlayerInventory>("Player Inventory");
	
	PlayerSpringArm = CreateDefaultSubobject<USpringArmComponent>("Player Spring Arm Camera");
	PlayerSpringArm->TargetArmLength = 0;
	PlayerSpringArm->bUsePawnControlRotation = true;
	PlayerSpringArm->TargetArmLength = 500.f;
	PlayerSpringArm->SetupAttachment(GetMesh());
	
	PlayerCamera = CreateDefaultSubobject<UCameraComponent>("Player Camera");
	PlayerCamera->SetupAttachment(PlayerSpringArm);
}

```

and the call for the line trace is here

```auto
	FHitResult Hit;
	bool bSuccess = bLineTrace(Hit);
	
	
	if (bSuccess)
	{
		AActor* HitActor = Hit.GetActor();
		if (HitActor != nullptr)
		{
			PlayerInventory->AddItemToInventory(HitActor);
		}
		UE_LOG(LogTemp, Warning, TEXT("Name is %s"), Hit.GetActor());
	}

```
