Easy way to focus and frame camera on selected object with blueprint? Like the F shortcut of editor

I want to develop a functionality where a user will be able to press a button that move the focus of the camera to a selected object and reposition the camera (with a fixed FoV) to frame the object correctly.

In face, I want to reproduce the behavior of the F shortcut in the editor:

  • In the editor, you can select an object
  • You can press F key
  • The camera move, put the select object in the center of the view and adjust the distance (arm length) to make the whole object visible.

Is there an easy way to reproduce that in blueprint? I’m actually doing trigonometry stuff and using bounding box size but I’m pretty sure there is a better way. I don’t want to recreate a feature that may be already accessible (and already developed in the editor).


Did you ever find a solution ?

One possible solution is to attach a Camera to your object so that the whole object is visible and then use Set View Target With Blend when player presses F key. This will smoothly change the view from your current camera to the object’s camera.

You can line trace to the object and move to the edge of the bounding box. I answered this in great detail some time ago, but can’t find it…