4.126: Somewhat Shorter Refactor?

I completed the challenge, saved my changes as backups, and then proceeded to follow the instructors methods.

I found that mine was a little shorter in some regards, but longer in others. PlayerViewPortLocation and Rotation, as well as the EndLineTrace became their own variables, while the rest of the code became a new function. The code set the variables and the rest took care of itself:


//Checks the Player Location and Viewport rotation 
void UGrabber::GetLineEndTrace()
			OUT PlayerViewPointLocation, 
			OUT PlayerViewPointRotation
	LineEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;

This function was then placed in the TickComponent so to be checked every frame, updating the variables in the .h as needed.



	float Reach = 100.f;
	void GetLineEndTrace();
	FVector LineEnd;
	FVector PlayerViewPointLocation;
	FRotator PlayerViewPointRotation;

I compiled… it ran through.
I pressed play… it worked.

So seems good to me.

As for the teacher’s code, I learned that an equation can be the return value, and that the function can be the variable in a parameter. It makes sense once you see it, even if you do not think of it at the time.


You are right about your last statement. Also great job for pushing yourself on the challenges! Keep up the great work!

1 Like

Privacy & Terms