Filling out Signatures

Hello forum,

I’m curious about something that I noticed in this lecture. During the video, Ben uses the LineTraceSingleByChannel() method and in order to do so, he provides it with a hit result, a start location, an end location and a collision type.

However, in the Unreal documentation, this method calls for two additional lines, query parameters and response parameters.

I was under the impression that we had to complete every portion of the signature for these Unreal methods to operate correctly? In another video, we even created a “camera direction” variable that we didn’t even need just to complete a signature.

Any insight into this would be very much appreciated.

Cheers.

The last parameter has a default value

const FCollisionQueryParams& Params = FCollisionQueryParams::DefaultQueryParam

Parameters with default values aren’t needed unless you don’t want the default. And you can’t skip parameters, as in if there was something like

Something(int a, int b = 10, int c = 20);

and you want to keep b’s default but not c’s. You still need to go through the whole list to change c’s.

Hello Den

  1. why we can’t use crosshair position as a StartPosition for LineTraceSingleByChannel() instead of Camere position. Like this:

     int32 ViewportSizeX, ViewportSizeY; 
     GetViewportSize(ViewportSizeX, ViewportSizeY);
    
     FVector2D CrosshairPosiotn(ViewportSizeX / 2, ViewportSizeY / 3);
     FVector StartPosiotion(CrosshairPosition.X, CrosshairPostion.Y, 0); //  Did I create postion in the World or not?
    
     FVector LookDiretion;
     DeprojectScreenPositionToWorld( CrosshairPosition.X, CrosshairPosition.Y, Camera, LookDirection );
    
     FVector EndLocation = StartPosiotion + LookDiretion * 1000000;
    
     FHitResult HitResult;
     GetWorld()->LineTraceSingleByChannel( HitResult, StartPosition, EndLocation, 
            ECollisoinChannel::ECC_Visibility);
    

on other hand Camera position and AimPoint posiont is not same therefor aiming isn’t Properly

  1. Because that’s the location on the 2d screen. It’s only going to have an X and Y, it wouldn’t be in the world.

Not sure what you mean by the other thing.

  1. Crosshair position is only Screen position and by this order:
    FVector StartPosiotion(CrosshairPosition.X, CrosshairPostion.Y, 0); I can’t convert it World location. did I correct understand?

  2. Ben takes Camera postion for StartLocation problem is that my Camera Location is higher than Crosshair positon therefor if I want to aim the Tank I have to lower down Crosshair, which is shown in the photo.
    I can change my camera position and equal it Crosshair postion but it also change viewpoint
    Is there anyway to start LineTrace from Crosshair position?

  1. With that, no. All you’re doing there is converting a FVector2D to a FVector.

    struct FVector2D
    {
        FVector2D(float x, float y) { X = x; Y = y }
        float X;
        float Y;
    }; 
    
    struct FVector
    {
        FVector(float x, float y, float z) { X = x; Y = y; Z = z; }
        float X;
        float Y;
        float Z;
    }
    int main()
    {
        FVector2D CrosshairPosition(1.f,2.f);
        FVector Start(CrosshairPosition.X, CrosshairPosition.Y, 0.f);
    }
    

    This is basically what you did… add a 0.

  2. Not sure why that would matter unless the object you are looking at is really close. They should both hit the same thing.

I think the problem is logical because Camera position is above to Crosshair outcome this aiming is not matching Crosshair. do you know how i can resolve this problem?
I know solution if I use GetHitResultAtScreenPosition() function but it significantly change my code and I want to follow the course

No I was wrong. My Aimpoint was attached wrongly. I solved the problem

1 Like

Privacy & Terms