Please advise how to convert this code from UE4 to UE5

Most of the code can be ignored and complies fine but the final line of the GetWorld()->LineTraceSingleByChannel(

FCollisionQueryParams(ECollisionChannel::ECC_Camera), returns :
no instance of constructor matches the argument list argument types are: (ECollisionChannel)

So how can I re-write this to work on UE5? would appreciate any help

thanks in advance

Xander
Code:

void ABeamWeaponActor::Fire()
{
	FHitResult HitResult;
	GetWorld()->LineTraceSingleByChannel(
		HitResult,
		LaserMeshComponent->GetComponentLocation(),
		LaserMeshComponent->GetComponentLocation() + (LaserMeshComponent->GetForwardVector().GetSafeNormal() * BeamMaxLength),
		ECollisionChannel::ECC_Camera,
		FCollisionQueryParams(ECollisionChannel::ECC_Camera)
	);

	float BeamLength = BeamMaxLength;

	if(HitResult.GetActor())
	{
		FVector Direction;
		(HitResult.ImpactPoint - LaserMeshComponent->GetComponentLocation()).ToDirectionAndLength(Direction, BeamLength);

		FHitResult HitInfo;
		UGameplayStatics::ApplyDamage(HitResult.GetActor(), DamagePerSecond * DeltaTime, GetInstigatorController(), this, UDamageType::StaticClass());
	}

	FVector BeamVector = FVector(BeamLength, 15.f, 15.f);

	LaserMeshComponent->SetWorldScale3D(BeamVector);
}

FCollisionQueryParams(ECollisionChannel::ECC_Camera)

What is this supposed to be, anyway? I can’t see any CollisionChannel parameters neither in FCollisionQueryParams constructors, nor in the FCollisionQueryParams struct itself. If you want to setup custom parameters, declare it before the trace and set it up; otherwise just remove the Params altogether, there’s a default value anyway.

So either:

FHitResult HitResult;
FCollisionQueryParams Params;
// Set Params Here
GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECollisionChannel::ECC_Camera, Params);

or:

FHitResult HitResult;
GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECollisionChannel::ECC_Camera);
1 Like

I pulled it from GitHub - BillyOMahony/Spaceship: Unreal Engine 4 Spaceship player and AI controller. Also includes VR FPS controller, pickupable and firable weapons, etc., so I have yet to follow through all the lines of code, im not particularly familar with UE function code as I normally work on unity, and not entirely sure what it does either, but i assumed there was some reason it was done like that and once it “worked” I would eventually work it out, at least by the name and descriptions on mouseover I assumed it was somehow related to how the engine handles ray traced feedback.

Having looked up the documentation part of the doc for ue5 seems removed vs ue4 but it still seems to include both, but it seems for whatever reason Params whatever it does no longer accepts a eclollsionchannel type value by default, so wondered if there was some other way to go about it without manually overloading it, it is true in mean time i simply removed params to make it compile, but unsure if i stripped any functionality from it to do so, hence the question here.

I gone for

FHitResult HitResult;
	GetWorld()->LineTraceSingleByChannel(
		HitResult,
		LaserMeshComponent->GetComponentLocation(),
		LaserMeshComponent->GetComponentLocation() + (LaserMeshComponent->GetForwardVector().GetSafeNormal() * BeamMaxLength),
		ECollisionChannel::ECC_Camera,
		FCollisionQueryParams()
	);

for now, which compiles, but without a thorough understanding i dont know if doing it like that has removed anything or not xD

Full code for this: https://github.com/BillyOMahony/Spaceship/blob/master/Source/Spaceship/Weapon/BeamWeaponActor.cpp

I do get the impression this was probably done by a college student as part of their studies, so not sure if he/she/it/goat entirely knew what they was doing either, but probably more so than me as I not touched UE code in several versions(since ue3) time xD, so it seemed easier to pull in this code and modify it then try to write one myself from scratch, and where I to write one from scratch I would benefit from fully understanding this first in either case.

1 Like

It was 3 years ago. Maybe in previous versions there was a constructor that would create FCollisionQueryParams based on a specific collision channel.

1 Like