My solution to not repeat the ViewPoint Code

in the unreal engine course lecture 94 ben shows us how to refactor the code in the grabber class. in one instance he made two function that have the same exact code to obtain the players viewpoint and update the Location and Rotation variables. One to return the end of the raycast line and one for the beginning.


Ben says its Ok to duplicate base code as they are needed to return the two different components. But what if instead of making two separate functions, you stuck to only one and is controlled through parameters?

I propose we name the function GetReachLine (FString) which will take a string as a parameter. as arguments I would either type out “End” or “Start” and respectively in the code I would check what was written and return the appropriate variable accordingly.

not sure if what I proposed is better so any feed back on this would help a lot, thank you

Instead of typing out a string, you could just use an enum, const’s, or something else.

You could even create two additional functions that already have them typed and just call parameter less functions.

Since its only two options, you could just use boolean.

You could use int.

You could use a new class.

You could… you could. You could :slight_smile:

1 Like

true :smile:

1 Like

Privacy & Terms