Change Near Clip Plane In Game


I had an idea for the graphical implementation of scopes in a fps game and wanted to test it today, but I forgot that camera components in UE4 don’t have a near clip plane distance attribute. I know that you can set the near clip value in the config, but I need to change it in game. Ideally that could be solved by adding a NearClipPlane variable to cameras (which a staff member wrote Epic would be considering), however I would also be happy with a workaround.

Thank you!

You can actually change that value at runtime and see the new clipping parameters take effect. If you wanted to, you could potentially save a float for as many near clip values as you want and change any of the values during an event or in a tick. Then use the console command “r.SetNearClipPlane” to apply it to your active camera (and all other cameras you switch to until you revert the Near Clip back). If you’re using blueprints then you can use the “ExecuteConsoleCommand” node to automate the process for you.

I’m not entirely sure how slow it is to be calling a console command every frame, but certainly it isn’t recommended. If you’re concerned about speed then you can probably find the internal functions being called and avoid the console completely. To be honest though, I use the ExecuteConsoleCommand node a lot and have used it for this exact purpose =P

Thank you PhilipRamirez!

I searched the source for the consolde comand in the source code and found out that it changes the global “GNearClippingPlane” float value. I don’t think you can modify this value in Blueprints, but in C++ you can simply change it to whatever you want in runtime and it will work.