Look at cursor - going from Blueprint to c++

Hello there!
Recently I wanted to make my character to look at cursor so I did a prototype in blueprints. Now I wanted to transfer it to c++ but my knowledge about UE4 is apparently too small because I’m stuck. Any advice? Should I try to “translate” every node? Only those important? What if I couldn’t find equivalent for “Get Hit Result Under Cursor by Channel”?

Thanks in advance!

when searching for c++ documentation, you should leave out all the spaces from the function names.
so if you search for “GetHitResultUnderCursorbyChannel”, the first result should be:


you may need to search for a few documentation pages like that, for each node you want to translate, then maybe search a bit in the source code for examples where they use something similar, then piece together a function that almost works, then you can fix all the errors until it works, like when it complains about ETeleportType being needed for SetActorRotation, just search for an example of SetActorRotation in the source code, or search for ETeleportType in the source, but you probably wont find documentation on Enums like that online… so searching the source code is the best way to find what you need.

i haven’t tested this code, i just threw it together combining a couple of examples. it might be a good start, but probably has errors:

void AMyPawnThing::Tick(float DeltaSeconds)
	APlayerController* PlayerController = Cast<APlayerController>(GetController());  
	if (PlayerController != nullptr)  
		FHitResult TraceResult(ForceInit);  
		PlayerController->GetHitResultUnderCursor(ECollisionChannel::ECC_WorldDynamic, true, TraceResult);  		
		SetActorRotation( FRotator( 0 , FindLookAtRotation(this.GetActorLocation(), TraceResult.Location ).Yaw , 0 ), ETeleportType::None );

The only thing it lacked was UKismetMathLibrary:: before FindLookAtRotation. Thanks! :slight_smile: