How to toggle between multiple camera with a UMG button?

Hello, I’m trying to toggle through different cameras with a single button in my GUI. I’ve already read through various posts, but unfortunately I can’t get any further because I’m still quite new to Unreal. Can someone help me please?

Thank you!

Do you need something like this? getting a list of the cameras in the scene, then switching between them in a loop

1 Like

If the cams are components in the character class you should be calling events in the class to toggle. Doing it this way encapsulates the functionality to the owning actor.

Overall, code like this should never be in UMG.

1 Like

As above, dispatch a click from the widget to the actor with the cameras. Cycling example:

First of all, thank you very much for your answer, I really appreciate it.
I’ve looked at the different options, but I’m still a little helpless as to how to implement it. I think I would like to work with just a single camera parented to a spring arm. How can I save the different positions of the camera and then trigger them with a button in the UMG?
Is it also possible to store different camera values such as focal length in these different positions?

To work with a single camera, you’d need a place to store the data for it to use.

In the Content Browser create a struct to hold your data:

image

You can add more data.


In the actor that holds the camera component:

  • create a widget and bind the button
  • create an array defining the desired camera setups:

Store the data here. Cycling stays the same.


There is a way to use presets by name but not sure if you can define your own. Probably? May be worth looking into. This type of camerawork is not my domain.

Also, the above is totally untested but could / should work. fingers crossed

Thanks a lot for this!!! I’ve recreated it as best as I can but I’m getting error messages. I also do not know how I can connect the camera with the variables.
The movement of the camera is controlled via the Sphere (Spring Arm), do I have to create a second structure for this?

  • create a new Int variable for this and plug it in:

image

It’s responsible for holding the index of the settings we want to use.

  • this bit:

image

Rather than promoting new variables, use the camera reference to assign data:

image

Drag a wire from the camera node and search for what you need.

Perfect, thank you so much, now it works!!!

Sorry one more Question, how can iget to the next position with a click on the same button?

This generates an iterator that fetches the next element from the array:

And modulo wraps the value so we do not exceed the bounds. The variable should probably be Set for clarity but it should work as is.

I might be misunderstanding what you mean by next position. If you mean the next predefined camera location, it’s is included in the script already in the form of a transform.

Now i got it, thank you so much for your help!

1 Like